示例#1
0
/*
 * Erase a range of element in an map.
 */
void map_erase_range(map_t* pmap_map, map_iterator_t it_begin, map_iterator_t it_end)
{
    assert(pmap_map != NULL);
    assert(_pair_is_inited(&pmap_map->_pair_temp));
    assert(_GET_MAP_CONTAINER_TYPE(it_begin) == _MAP_CONTAINER);
    assert(_GET_MAP_ITERATOR_TYPE(it_begin) == _BIDIRECTIONAL_ITERATOR);
    assert(_GET_MAP_CONTAINER_TYPE(it_end) == _MAP_CONTAINER);
    assert(_GET_MAP_ITERATOR_TYPE(it_end) == _BIDIRECTIONAL_ITERATOR);
    assert(_GET_MAP_CONTAINER(it_begin) == pmap_map && _GET_MAP_CONTAINER(it_end) == pmap_map);

#ifdef CSTL_MAP_AVL_TREE
    _avl_tree_erase_range(&pmap_map->_t_tree, it_begin, it_end);
#else
    _rb_tree_erase_range(&pmap_map->_t_tree, it_begin, it_end);
#endif
}
示例#2
0
/**
 * Inserts an unique element into a map with hint position.
 */
map_iterator_t map_insert_hint(map_t* pmap_map, map_iterator_t it_hint, const pair_t* cppair_pair)
{
    assert(pmap_map != NULL);
    assert(cppair_pair != NULL);
    assert(_pair_is_inited(&pmap_map->_pair_temp));
    assert(_pair_is_inited(cppair_pair));
    assert(_GET_MAP_CONTAINER_TYPE(it_hint) == _MAP_CONTAINER);
    assert(_GET_MAP_ITERATOR_TYPE(it_hint) == _BIDIRECTIONAL_ITERATOR);
    assert(_GET_MAP_CONTAINER(it_hint) == pmap_map);

    /* set key less function and value less function */
    ((pair_t*)cppair_pair)->_bfun_mapkeycompare = pmap_map->_bfun_keycompare;
    ((pair_t*)cppair_pair)->_bfun_mapvaluecompare = pmap_map->_bfun_valuecompare;

    assert(_map_same_pair_type_ex(&pmap_map->_pair_temp, cppair_pair));

#ifdef CSTL_MAP_AVL_TREE
    it_hint = _avl_tree_insert_unique(&pmap_map->_t_tree, cppair_pair);
#else
    it_hint = _rb_tree_insert_unique(&pmap_map->_t_tree, cppair_pair);
#endif

    _GET_CONTAINER(it_hint) = pmap_map;
    _GET_MAP_CONTAINER_TYPE(it_hint) = _MAP_CONTAINER;
    _GET_MAP_ITERATOR_TYPE(it_hint) = _BIDIRECTIONAL_ITERATOR;

    return it_hint;
}
示例#3
0
bool_t _map_iterator_before(
    const map_iterator_t* cpt_iteratorfirst, const map_iterator_t* cpt_iteratorsecond)
{
    assert(cpt_iteratorfirst != NULL && cpt_iteratorsecond != NULL);
    assert(
        _GET_MAP_CONTAINER_TYPE(cpt_iteratorfirst) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(cpt_iteratorfirst) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER_TYPE(cpt_iteratorsecond) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(cpt_iteratorsecond) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER(cpt_iteratorfirst) == _GET_MAP_CONTAINER(cpt_iteratorsecond));

#ifdef CSTL_MAP_AVL_TREE
    return _avl_tree_iterator_before(cpt_iteratorfirst, cpt_iteratorsecond);
#else
    return _rb_tree_iterator_before(cpt_iteratorfirst, cpt_iteratorsecond);
#endif
}
示例#4
0
int _map_iterator_distance(
    const map_iterator_t* cpt_begin, const map_iterator_t* cpt_end)
{
    assert(cpt_begin != NULL && cpt_end != NULL);
    assert(
        _GET_MAP_CONTAINER_TYPE(cpt_begin) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(cpt_begin) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER_TYPE(cpt_end) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(cpt_end) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER(cpt_begin) == _GET_MAP_CONTAINER(cpt_end));

#ifdef CSTL_MAP_AVL_TREE
    return _avl_tree_iterator_distance(cpt_begin, cpt_end);
#else
    return _rb_tree_iterator_distance(cpt_begin, cpt_end);
#endif
}
示例#5
0
void map_erase_range(
    map_t* pt_map, map_iterator_t t_begin, map_iterator_t t_end)
{
    assert(pt_map != NULL);
    assert(
        _GET_MAP_CONTAINER_TYPE(&t_begin) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(&t_begin) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER_TYPE(&t_end) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(&t_end) == _BIDIRECTIONAL_ITERATOR);
    assert(
        _GET_MAP_CONTAINER(&t_begin) == pt_map &&
        _GET_MAP_CONTAINER(&t_end) == pt_map);

#ifdef CSTL_MAP_AVL_TREE
    _avl_tree_erase_range(_GET_MAP_AVL_TREE(pt_map), t_begin, t_end);
#else
    _rb_tree_erase_range(_GET_MAP_RB_TREE(pt_map), t_begin, t_end);
#endif
}
示例#6
0
/**
 * Inserts an range of unique element into a map.
 */
void map_insert_range(map_t* pmap_map, map_iterator_t it_begin, map_iterator_t it_end)
{
    map_iterator_t it_iter;

    assert(pmap_map != NULL);
    assert(_pair_is_inited(&pmap_map->_pair_temp));
    assert(_GET_MAP_CONTAINER_TYPE(it_begin) == _MAP_CONTAINER);
    assert(_GET_MAP_ITERATOR_TYPE(it_begin) == _BIDIRECTIONAL_ITERATOR);
    assert(_GET_MAP_CONTAINER_TYPE(it_end) == _MAP_CONTAINER);
    assert(_GET_MAP_ITERATOR_TYPE(it_end) == _BIDIRECTIONAL_ITERATOR);
    assert(_GET_MAP_CONTAINER(it_begin) != pmap_map);
    assert(_GET_MAP_CONTAINER(it_end) != pmap_map);
    assert(_GET_MAP_CONTAINER(it_begin) == _GET_MAP_CONTAINER(it_end));
    assert(_map_same_pair_type(&pmap_map->_pair_temp, &_GET_MAP_CONTAINER(it_begin)->_pair_temp));

    for(it_iter = it_begin; !iterator_equal(it_iter, it_end); it_iter = iterator_next(it_iter))
    {
        map_insert(pmap_map, (pair_t*)iterator_get_pointer(it_iter));
    }
}
示例#7
0
void map_insert_range(
    map_t* pt_map, map_iterator_t t_begin, map_iterator_t t_end)
{
    map_iterator_t t_iterator;

    assert(pt_map != NULL);
    assert(
        _GET_MAP_CONTAINER_TYPE(&t_begin) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(&t_begin) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER_TYPE(&t_end) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(&t_end) == _BIDIRECTIONAL_ITERATOR);
    assert(
        _GET_MAP_CONTAINER(&t_begin) != pt_map &&
        _GET_MAP_CONTAINER(&t_end) != pt_map &&
        _GET_MAP_CONTAINER(&t_begin) == _GET_MAP_CONTAINER(&t_end));

    for(t_iterator = t_begin;
        !iterator_equal(&t_iterator, t_end);
        iterator_next(&t_iterator))
    {
        map_insert(pt_map, (pair_t*)iterator_get_pointer(&t_iterator));
    }
}
示例#8
0
bool_t _map_iterator_equal(
    const struct _tagmap* cpt_map, 
    const map_iterator_t* cpt_iterator,
    map_iterator_t t_iterator)
{
    assert(cpt_map != NULL && cpt_iterator != NULL);
    assert(
        _GET_MAP_CONTAINER_TYPE(cpt_iterator) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(cpt_iterator) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER_TYPE(&t_iterator) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(&t_iterator) == _BIDIRECTIONAL_ITERATOR);
    assert(
        _GET_MAP_CONTAINER(cpt_iterator) == cpt_map &&
        _GET_MAP_CONTAINER(&t_iterator) == cpt_map);

#ifdef CSTL_MAP_AVL_TREE
    return _avl_tree_iterator_equal(
        _GET_MAP_AVL_TREE(cpt_map), cpt_iterator, t_iterator);
#else
    return _rb_tree_iterator_equal(
        _GET_MAP_RB_TREE(cpt_map), cpt_iterator, t_iterator);
#endif
}
示例#9
0
void _map_iterator_prev(
    const struct _tagmap* cpt_map, map_iterator_t* pt_iterator)
{
    assert(cpt_map != NULL && pt_iterator != NULL);
    assert(
        _GET_MAP_CONTAINER_TYPE(pt_iterator) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(pt_iterator) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER(pt_iterator) == cpt_map);

#ifdef CSTL_MAP_AVL_TREE
    _avl_tree_iterator_prev(_GET_MAP_AVL_TREE(cpt_map), pt_iterator);
#else
    _rb_tree_iterator_prev(_GET_MAP_RB_TREE(cpt_map), pt_iterator);
#endif
}
示例#10
0
void map_init_copy_range_cmp(
    map_t* pt_mapdest, map_iterator_t t_begin, map_iterator_t t_end,
    int (*pfun_key_cmp)(const void*, const void*))
{
    assert(pt_mapdest != NULL);
    assert(
        _GET_MAP_CONTAINER_TYPE(&t_begin) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(&t_begin) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER_TYPE(&t_end) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(&t_end) == _BIDIRECTIONAL_ITERATOR);
    assert(
        _GET_MAP_CONTAINER(&t_begin) != pt_mapdest &&
        _GET_MAP_CONTAINER(&t_end) != pt_mapdest &&
        _GET_MAP_CONTAINER(&t_begin) == _GET_MAP_CONTAINER(&t_end));
    assert(
        pt_mapdest->_t_pair._t_firsttypesize == 
            _GET_MAP_CONTAINER(&t_begin)->_t_pair._t_firsttypesize &&
        pt_mapdest->_t_pair._t_secondtypesize ==
            _GET_MAP_CONTAINER(&t_begin)->_t_pair._t_secondtypesize);
    assert(
        strncmp(
            pt_mapdest->_t_pair._sz_firsttypename,
            _GET_MAP_CONTAINER(&t_begin)->_t_pair._sz_firsttypename,
            _ELEM_TYPE_NAME_SIZE) == 0 &&
        strncmp(
            pt_mapdest->_t_pair._sz_secondtypename,
            _GET_MAP_CONTAINER(&t_begin)->_t_pair._sz_secondtypename,
            _ELEM_TYPE_NAME_SIZE) == 0);

    /* initialize dest map with src map attribute */
    map_init(pt_mapdest);
    pt_mapdest->_t_pair._pfun_first_cmp = pfun_key_cmp;
    /* insert all element from src to dest */
    if(!map_empty(_GET_MAP_CONTAINER(&t_begin)))
    {
        map_insert_range(pt_mapdest, t_begin, t_end);
    }
}
示例#11
0
void _map_iterator_get_value(
    const struct _tagmap* cpt_map, 
    const map_iterator_t* cpt_iterator, 
    void* pv_value)
{
    assert(cpt_map != NULL && cpt_iterator != NULL && pv_value != NULL);
    assert(
        _GET_MAP_CONTAINER_TYPE(cpt_iterator) == _MAP_CONTAINER &&
        _GET_MAP_ITERATOR_TYPE(cpt_iterator) == _BIDIRECTIONAL_ITERATOR &&
        _GET_MAP_CONTAINER(cpt_iterator) == cpt_map);

#ifdef CSTL_MAP_AVL_TREE
    _avl_tree_iterator_get_value(
        _GET_MAP_AVL_TREE(cpt_map), cpt_iterator, pv_value);
#else
    _rb_tree_iterator_get_value(
        _GET_MAP_RB_TREE(cpt_map), cpt_iterator, pv_value);
#endif
}
示例#12
0
/**
 * Initialize map container with specific range and compare function.
 */
void map_init_copy_range_ex(map_t* pmap_dest, map_iterator_t it_begin, map_iterator_t it_end, binary_function_t bfun_keycompare)
{
    assert(pmap_dest != NULL);
    assert(_pair_is_created(&pmap_dest->_pair_temp));
    assert(_GET_MAP_CONTAINER_TYPE(it_begin) == _MAP_CONTAINER);
    assert(_GET_MAP_ITERATOR_TYPE(it_begin) == _BIDIRECTIONAL_ITERATOR);
    assert(_GET_MAP_CONTAINER_TYPE(it_end) == _MAP_CONTAINER);
    assert(_GET_MAP_ITERATOR_TYPE(it_end) == _BIDIRECTIONAL_ITERATOR);
    assert(_GET_MAP_CONTAINER(it_begin) != pmap_dest);
    assert(_GET_MAP_CONTAINER(it_end) != pmap_dest);
    assert(_GET_MAP_CONTAINER(it_begin) == _GET_MAP_CONTAINER(it_end));
    assert(_map_same_pair_type(&pmap_dest->_pair_temp, &_GET_MAP_CONTAINER(it_begin)->_pair_temp));

    /* initialize dest map with src map attribute */
    map_init_ex(pmap_dest, bfun_keycompare);
    /* insert all element from src to dest */
    if(!map_empty(_GET_MAP_CONTAINER(it_begin)))
    {
        map_insert_range(pmap_dest, it_begin, it_end);
    }
}