Beispiel #1
0
/**
 * Return an iterator range that is equal to a specific element.
 */
range_t _set_equal_range_varg(const set_t* cpset_set, va_list val_elemlist)
{
    void*          pv_varg = NULL;
    range_t        r_range;

    assert(cpset_set != NULL);

    pv_varg = _alloc_allocate(&((set_t*)cpset_set)->_t_tree._t_allocator, _GET_SET_TYPE_SIZE(cpset_set), 1);
    assert(pv_varg != NULL);
    _set_get_varg_value_auxiliary((set_t*)cpset_set, val_elemlist, pv_varg);

#ifdef CSTL_SET_AVL_TREE
    r_range = _avl_tree_equal_range(&cpset_set->_t_tree, pv_varg);
#else
    r_range = _rb_tree_equal_range(&cpset_set->_t_tree, pv_varg);
#endif

    _set_destroy_varg_value_auxiliary((set_t*)cpset_set, pv_varg);
    _alloc_deallocate(&((set_t*)cpset_set)->_t_tree._t_allocator, pv_varg, _GET_SET_TYPE_SIZE(cpset_set), 1);

    _ITERATOR_CONTAINER(r_range.it_begin) = (set_t*)cpset_set;
    _SET_ITERATOR_CONTAINER_TYPE(r_range.it_begin) = _SET_CONTAINER;
    _SET_ITERATOR_ITERATOR_TYPE(r_range.it_begin) = _BIDIRECTIONAL_ITERATOR;

    _ITERATOR_CONTAINER(r_range.it_end) = (set_t*)cpset_set;
    _SET_ITERATOR_CONTAINER_TYPE(r_range.it_end) = _SET_CONTAINER;
    _SET_ITERATOR_ITERATOR_TYPE(r_range.it_end) = _BIDIRECTIONAL_ITERATOR;

    return r_range;
}
Beispiel #2
0
/**
 * Inserts an unique element into a set with hint.
 */
set_iterator_t _set_insert_hint_varg(set_t* pset_set, set_iterator_t it_hint, va_list val_elemlist)
{
    void* pv_varg = NULL;

    assert(pset_set != NULL);

    pv_varg = _alloc_allocate(&pset_set->_t_tree._t_allocator, _GET_SET_TYPE_SIZE(pset_set), 1);
    assert(pv_varg != NULL);
    _set_get_varg_value_auxiliary(pset_set, val_elemlist, pv_varg);

#ifdef CSTL_SET_AVL_TREE
    it_hint = _avl_tree_insert_unique(&pset_set->_t_tree, pv_varg);
#else
    it_hint = _rb_tree_insert_unique(&pset_set->_t_tree, pv_varg);
#endif

    _set_destroy_varg_value_auxiliary(pset_set, pv_varg);
    _alloc_deallocate(&pset_set->_t_tree._t_allocator, pv_varg, _GET_SET_TYPE_SIZE(pset_set), 1);

    _ITERATOR_CONTAINER(it_hint) = pset_set;
    _SET_ITERATOR_CONTAINER_TYPE(it_hint) = _SET_CONTAINER;
    _SET_ITERATOR_ITERATOR_TYPE(it_hint) = _BIDIRECTIONAL_ITERATOR;

    return it_hint;
}
Beispiel #3
0
/**
 * Return an iterator to the first element that is greater than a specific element.
 */
set_iterator_t _set_upper_bound_varg(const set_t* cpset_set, va_list val_elemlist)
{
    void*          pv_varg = NULL;
    set_iterator_t it_iter;

    assert(cpset_set != NULL);

    pv_varg = _alloc_allocate(&((set_t*)cpset_set)->_t_tree._t_allocator, _GET_SET_TYPE_SIZE(cpset_set), 1);
    assert(pv_varg != NULL);
    _set_get_varg_value_auxiliary((set_t*)cpset_set, val_elemlist, pv_varg);

#ifdef CSTL_SET_AVL_TREE
    it_iter = _avl_tree_upper_bound(&cpset_set->_t_tree, pv_varg);
#else
    it_iter = _rb_tree_upper_bound(&cpset_set->_t_tree, pv_varg);
#endif

    _set_destroy_varg_value_auxiliary((set_t*)cpset_set, pv_varg);
    _alloc_deallocate(&((set_t*)cpset_set)->_t_tree._t_allocator, pv_varg, _GET_SET_TYPE_SIZE(cpset_set), 1);

    _ITERATOR_CONTAINER(it_iter) = (set_t*)cpset_set;
    _SET_ITERATOR_CONTAINER_TYPE(it_iter) = _SET_CONTAINER;
    _SET_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;

    return it_iter;
}
Beispiel #4
0
/**
 * Create slist iterator.
 */
slist_iterator_t _create_slist_iterator(void)
{
    slist_iterator_t it_iter;

    _SLIST_ITERATOR_ITERATOR_TYPE(it_iter) = _FORWARD_ITERATOR;
    _SLIST_ITERATOR_CONTAINER_TYPE(it_iter) = _SLIST_CONTAINER;
    _ITERATOR_CONTAINER(it_iter) = NULL;
    _SLIST_ITERATOR_COREPOS(it_iter) = NULL;

    return it_iter;
}
/**
 * Return an iterator range that is equal to a specific element.
 */
range_t _hash_multimap_equal_range_varg(const hash_multimap_t* cphmmap_map, va_list val_elemlist)
{
    range_t  r_range;

    assert(cphmmap_map != NULL);

    _type_get_varg_value(&((hash_multimap_t*)cphmmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cphmmap_map->_pair_temp._pv_first);

    r_range = _hashtable_equal_range(&cphmmap_map->_t_hashtable, &cphmmap_map->_pair_temp);

    _ITERATOR_CONTAINER(r_range.it_begin) = (hash_multimap_t*)cphmmap_map;
    _HASH_MULTIMAP_ITERATOR_CONTAINER_TYPE(r_range.it_begin) = _HASH_MULTIMAP_CONTAINER;
    _HASH_MULTIMAP_ITERATOR_ITERATOR_TYPE(r_range.it_begin) = _BIDIRECTIONAL_ITERATOR;

    _ITERATOR_CONTAINER(r_range.it_end) = (hash_multimap_t*)cphmmap_map;
    _HASH_MULTIMAP_ITERATOR_CONTAINER_TYPE(r_range.it_end) = _HASH_MULTIMAP_CONTAINER;
    _HASH_MULTIMAP_ITERATOR_ITERATOR_TYPE(r_range.it_end) = _BIDIRECTIONAL_ITERATOR;

    return r_range;
}
Beispiel #6
0
/**
 * Create new vector iterator.
 */
vector_iterator_t _create_vector_iterator(void)
{
    vector_iterator_t it_iter;

    _VECTOR_ITERATOR_COREPOS(it_iter) = NULL;
    _ITERATOR_CONTAINER(it_iter) = NULL;
    _VECTOR_ITERATOR_CONTAINER_TYPE(it_iter) = _VECTOR_CONTAINER;
    _VECTOR_ITERATOR_ITERATOR_TYPE(it_iter) = _RANDOM_ACCESS_ITERATOR;

    return it_iter;
}
/**
 * Create rb tree iterator.
 */
_rb_tree_iterator_t _create_rb_tree_iterator(void)
{
    _rb_tree_iterator_t it_iter;

    _RB_TREE_ITERATOR_COREPOS(it_iter) = NULL;
    _RB_TREE_ITERATOR_TREE_POINTER(it_iter) = NULL;

    _ITERATOR_CONTAINER(it_iter) = NULL;

    return it_iter;
}
/**
 * Create hashtable iterator.
 */
_hashtable_iterator_t _create_hashtable_iterator(void)
{
    _hashtable_iterator_t it_iter;

    _HASHTABLE_ITERATOR_BUCKETPOS(it_iter) = NULL;
    _HASHTABLE_ITERATOR_COREPOS(it_iter) = NULL;
    _HASHTABLE_ITERATOR_HASHTABLE_POINTER(it_iter) = NULL;

    _ITERATOR_CONTAINER(it_iter) = NULL;

    return it_iter;
}
Beispiel #9
0
/**
 * Return a iterator that points just beyond the end of vector container.
 */
vector_iterator_t vector_end(const vector_t* cpvec_vector)
{
    vector_iterator_t it_end;

    assert(cpvec_vector != NULL);
    assert(_vector_is_inited(cpvec_vector));

    it_end = _create_vector_iterator();
    _ITERATOR_CONTAINER(it_end) = (vector_t*)cpvec_vector;
    _VECTOR_ITERATOR_COREPOS(it_end) = cpvec_vector->_pby_finish;

    return it_end;
}
Beispiel #10
0
/**
 * Return a iterator to the first element in the vector container.
 */
vector_iterator_t vector_begin(const vector_t* cpvec_vector)
{
    vector_iterator_t it_begin; /* new vector iterator */

    assert(cpvec_vector != NULL);
    assert(_vector_is_inited(cpvec_vector));

    it_begin = _create_vector_iterator();
    _ITERATOR_CONTAINER(it_begin) = (vector_t*)cpvec_vector;
    _VECTOR_ITERATOR_COREPOS(it_begin) = cpvec_vector->_pby_start;

    return it_begin;
}
Beispiel #11
0
vector_reverse_iterator_t vector_rend(const vector_t* cpvec_vector)
{
    vector_reverse_iterator_t it_rend;

    assert(cpvec_vector != NULL);
    assert(_vector_is_inited(cpvec_vector));

    it_rend = _create_vector_iterator();
    _ITERATOR_CONTAINER(it_rend) = (vector_t*)cpvec_vector;
    _VECTOR_ITERATOR_COREPOS(it_rend) = cpvec_vector->_pby_start - _GET_VECTOR_TYPE_SIZE(cpvec_vector);

    return it_rend;
}
Beispiel #12
0
/**
 * Return an iterator that addresses the location succeeding the last element in the hash_set.
 */
hash_set_iterator_t hash_set_end(const hash_set_t* cphset_set)
{
    hash_set_iterator_t it_end;

    assert(cphset_set != NULL);

    it_end = _hashtable_end(&cphset_set->_t_hashtable);

    _ITERATOR_CONTAINER(it_end) = (hash_set_t*)cphset_set;
    _HASH_SET_ITERATOR_CONTAINER_TYPE(it_end) = _HASH_SET_CONTAINER;
    _HASH_SET_ITERATOR_ITERATOR_TYPE(it_end) = _BIDIRECTIONAL_ITERATOR;

    return it_end;
}
Beispiel #13
0
/**
 * Return an iterator range that is equal to a specific element.
 */
range_t _map_equal_range_varg(const map_t* cpmap_map, va_list val_elemlist)
{
    range_t r_range;

    assert(cpmap_map != NULL);
    assert(_pair_is_inited(&cpmap_map->_pair_temp));

    _type_get_varg_value(&((map_t*)cpmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cpmap_map->_pair_temp._pv_first);
#ifdef CSTL_MAP_AVL_TREE
    r_range = _avl_tree_equal_range(&cpmap_map->_t_tree, &cpmap_map->_pair_temp);
#else
    r_range = _rb_tree_equal_range(&cpmap_map->_t_tree, &cpmap_map->_pair_temp);
#endif

    _ITERATOR_CONTAINER(r_range.it_begin) = (map_t*)cpmap_map;
    _MAP_ITERATOR_CONTAINER_TYPE(r_range.it_begin) = _MAP_CONTAINER;
    _MAP_ITERATOR_ITERATOR_TYPE(r_range.it_begin) = _BIDIRECTIONAL_ITERATOR;
    _ITERATOR_CONTAINER(r_range.it_end) = (map_t*)cpmap_map;
    _MAP_ITERATOR_CONTAINER_TYPE(r_range.it_end) = _MAP_CONTAINER;
    _MAP_ITERATOR_ITERATOR_TYPE(r_range.it_end) = _BIDIRECTIONAL_ITERATOR;

    return r_range;
}
Beispiel #14
0
/**
 * Return an iterator that addresses the location succeeding the last element in the hash_multimap.
 */
hash_multimap_iterator_t hash_multimap_end(const hash_multimap_t* cphmmap_map)
{
    hash_multimap_iterator_t it_end;

    assert(cphmmap_map != NULL);
    assert(_pair_is_inited(&cphmmap_map->_pair_temp));

    it_end = _hashtable_end(&cphmmap_map->_t_hashtable);

    _ITERATOR_CONTAINER(it_end) = (hash_multimap_t*)cphmmap_map;
    _HASH_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_end) = _HASH_MULTIMAP_CONTAINER;
    _HASH_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_end) = _BIDIRECTIONAL_ITERATOR;

    return it_end;
}
/**
 * Find specific element.
 */
hash_multimap_iterator_t _hash_multimap_find_varg(const hash_multimap_t* cphmmap_map, va_list val_elemlist)
{
    hash_multimap_iterator_t it_iter;

    assert(cphmmap_map != NULL);

    _type_get_varg_value(&((hash_multimap_t*)cphmmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cphmmap_map->_pair_temp._pv_first);

    it_iter = _hashtable_find(&cphmmap_map->_t_hashtable, &cphmmap_map->_pair_temp);

    _ITERATOR_CONTAINER(it_iter) = (hash_multimap_t*)cphmmap_map;
    _HASH_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_iter) = _HASH_MULTIMAP_CONTAINER;
    _HASH_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;

    return it_iter;
}
Beispiel #16
0
set_iterator_t set_rend(const set_t* cpset_set)
{
    set_iterator_t it_rend;

    assert(cpset_set != NULL);

#ifdef CSTL_SET_AVL_TREE
    it_rend = _avl_tree_rend(&cpset_set->_t_tree);
#else
    it_rend = _rb_tree_rend(&cpset_set->_t_tree);
#endif

    _ITERATOR_CONTAINER(it_rend) = (set_t*)cpset_set;
    _SET_ITERATOR_CONTAINER_TYPE(it_rend) = _SET_CONTAINER;
    _SET_ITERATOR_ITERATOR_TYPE(it_rend) = _BIDIRECTIONAL_ITERATOR;

    return it_rend;
}
Beispiel #17
0
multiset_iterator_t multiset_rbegin(const multiset_t* cpmset_mset)
{
    multiset_iterator_t it_rbegin;

    assert(cpmset_mset != NULL);

#ifdef CSTL_MULTISET_AVL_TREE
    it_rbegin = _avl_tree_rbegin(&cpmset_mset->_t_tree);
#else
    it_rbegin = _rb_tree_rbegin(&cpmset_mset->_t_tree);
#endif

    _ITERATOR_CONTAINER(it_rbegin) = (multiset_t*)cpmset_mset;
    _MULTISET_ITERATOR_CONTAINER_TYPE(it_rbegin) = _MULTISET_CONTAINER;
    _MULTISET_ITERATOR_ITERATOR_TYPE(it_rbegin) = _BIDIRECTIONAL_ITERATOR;

    return it_rbegin;
}
Beispiel #18
0
/**
 * Return an iterator to the first element that is greater than a specific element.
 */
map_iterator_t _map_upper_bound_varg(const map_t* cpmap_map, va_list val_elemlist)
{
    map_iterator_t it_iter;

    assert(cpmap_map != NULL);
    assert(_pair_is_inited(&cpmap_map->_pair_temp));

    _type_get_varg_value(&((map_t*)cpmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cpmap_map->_pair_temp._pv_first);
#ifdef CSTL_MAP_AVL_TREE
    it_iter = _avl_tree_upper_bound(&cpmap_map->_t_tree, &cpmap_map->_pair_temp);
#else
    it_iter = _rb_tree_upper_bound(&cpmap_map->_t_tree, &cpmap_map->_pair_temp);
#endif

    _ITERATOR_CONTAINER(it_iter) = (map_t*)cpmap_map;
    _MAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MAP_CONTAINER;
    _MAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;

    return it_iter;
}
Beispiel #19
0
/**
 * Inserts an unique element into a hash_multimap.
 */
hash_multimap_iterator_t hash_multimap_insert(hash_multimap_t* phmmap_map, const pair_t* cppair_pair)
{
    hash_multimap_iterator_t it_iter;

    assert(phmmap_map != NULL);
    assert(cppair_pair != NULL);
    assert(_pair_is_inited(&phmmap_map->_pair_temp));
    assert(_pair_is_inited(cppair_pair));

    ((pair_t*)cppair_pair)->_bfun_mapkeycompare = phmmap_map->_bfun_keycompare;
    ((pair_t*)cppair_pair)->_bfun_mapvaluecompare = phmmap_map->_bfun_valuecompare;
    assert(_hash_multimap_same_pair_type_ex(&phmmap_map->_pair_temp, cppair_pair));

    /* insert int hashtable */
    it_iter = _hashtable_insert_equal(&phmmap_map->_t_hashtable, cppair_pair);

    _ITERATOR_CONTAINER(it_iter) = phmmap_map;
    _HASH_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_iter) = _HASH_MULTIMAP_CONTAINER;
    _HASH_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;

    return it_iter;
}
Beispiel #20
0
/**
 * Access an element with specific index.
 */
void* _map_at_varg(map_t* pmap_map, va_list val_elemlist)
{
    map_iterator_t it_iter;
    va_list val_elemlist_copy;

    assert(pmap_map != NULL);
    assert(_pair_is_inited(&pmap_map->_pair_temp));

    va_copy(val_elemlist_copy, val_elemlist);
    _type_get_varg_value(&pmap_map->_pair_temp._t_typeinfofirst, val_elemlist, pmap_map->_pair_temp._pv_first);
#ifdef CSTL_MAP_AVL_TREE
    it_iter = _avl_tree_insert_unique(&pmap_map->_t_tree, &pmap_map->_pair_temp);
#else
    it_iter = _rb_tree_insert_unique(&pmap_map->_t_tree, &pmap_map->_pair_temp);
#endif

    _ITERATOR_CONTAINER(it_iter) = pmap_map;
    _MAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MAP_CONTAINER;
    _MAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;

    if(iterator_equal(it_iter, map_end(pmap_map)))
    {
        it_iter = _map_find_varg(pmap_map, val_elemlist_copy);
    }

    va_end(val_elemlist_copy);

    /* char* */
    if(strncmp(_GET_MAP_SECOND_TYPE_BASENAME(pmap_map), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0)
    {
        return (char*)string_c_str((string_t*)((pair_t*)iterator_get_pointer(it_iter))->_pv_second);
    }
    else
    {
        return ((pair_t*)iterator_get_pointer(it_iter))->_pv_second;
    }
}