예제 #1
0
/**
 * Calculate the distance between two iterators.
 */
int _deque_iterator_minus(deque_iterator_t it_first, deque_iterator_t it_second)
{
    int n_span = 0;
    int n_prefix = 0;
    int n_suffix = 0;

    assert(_DEQUE_ITERATOR_CONTAINER(it_first) == _DEQUE_ITERATOR_CONTAINER(it_second));
    assert(_deque_iterator_belong_to_deque(_DEQUE_ITERATOR_CONTAINER(it_first), it_first));
    assert(_deque_iterator_belong_to_deque(_DEQUE_ITERATOR_CONTAINER(it_second), it_second));

    if(_deque_iterator_equal(it_first, it_second))
    {
        return 0;
    }
    else if(_deque_iterator_before(it_first, it_second))
    {
        n_span = (_DEQUE_ITERATOR_MAP_POINTER(it_second) - _DEQUE_ITERATOR_MAP_POINTER(it_first) - 1) * _DEQUE_ELEM_COUNT;
        n_prefix = (_DEQUE_ITERATOR_AFTERLAST_POS(it_first) - _DEQUE_ITERATOR_COREPOS(it_first)) /
            _GET_DEQUE_TYPE_SIZE(_DEQUE_ITERATOR_CONTAINER(it_first));
        n_suffix = (_DEQUE_ITERATOR_COREPOS(it_second) - _DEQUE_ITERATOR_FIRST_POS(it_second)) / 
            _GET_DEQUE_TYPE_SIZE(_DEQUE_ITERATOR_CONTAINER(it_second));
               
        return -(n_prefix + n_span + n_suffix);
    }
    else
    {
        n_span = (_DEQUE_ITERATOR_MAP_POINTER(it_first) - _DEQUE_ITERATOR_MAP_POINTER(it_second) - 1) * _DEQUE_ELEM_COUNT;
        n_prefix = (_DEQUE_ITERATOR_AFTERLAST_POS(it_second) - _DEQUE_ITERATOR_COREPOS(it_second)) /
            _GET_DEQUE_TYPE_SIZE(_DEQUE_ITERATOR_CONTAINER(it_second));
        n_suffix = (_DEQUE_ITERATOR_COREPOS(it_first) - _DEQUE_ITERATOR_FIRST_POS(it_first)) / 
            _GET_DEQUE_TYPE_SIZE(_DEQUE_ITERATOR_CONTAINER(it_first));
               
        return n_prefix + n_span + n_suffix;
    }
}
예제 #2
0
/**
 * Test two iterator are equal or not.
 */
bool_t iterator_equal(iterator_t it_first, iterator_t it_second)
{
    assert(_iterator_is_valid(it_first));
    assert(_iterator_is_valid(it_second));
    assert(_iterator_limit_type(it_first, _INPUT_ITERATOR));
    assert(_iterator_limit_type(it_second, _INPUT_ITERATOR));

    if (it_first._t_containertype != it_second._t_containertype) {
        return false;
    }

    switch (it_first._t_containertype) {
        case _VECTOR_CONTAINER:
            return _vector_iterator_equal(it_first, it_second);
            break;
        case _LIST_CONTAINER:
            return _list_iterator_equal(it_first, it_second);
            break;
        case _DEQUE_CONTAINER:
            return _deque_iterator_equal(it_first, it_second);
            break;
						/*
        case _SLIST_CONTAINER:
            return _slist_iterator_equal(it_first, it_second);
            break;
						*/
        case _SET_CONTAINER:
            return _set_iterator_equal(it_first, it_second);
            break;
        case _MAP_CONTAINER:
            return _map_iterator_equal(it_first, it_second);
            break;
        case _HASH_SET_CONTAINER:
            return _hash_set_iterator_equal(it_first, it_second);
            break;
        case _HASH_MAP_CONTAINER:
            return _hash_map_iterator_equal(it_first, it_second);
            break;
        case _BASIC_STRING_CONTAINER:
            return _basic_string_iterator_equal(it_first, it_second);
            break;
        default:
            assert(false);
            return false;
            break;
    }
}