Пример #1
0
/** exported function implementation section **/
void test_avl_tree(void)
{
    avl_tree_t t_tree = _create_avl_tree(sizeof(int), "int");
    avl_tree_t t_tree2 = _create_avl_tree(sizeof(int), "int");
    int n_value = 900;

    _avl_tree_init(&t_tree, NULL, NULL);
    _avl_tree_insert_equal(&t_tree, &n_value);
    printf("avl tree1 - size:%u, max_size:%u, empty:%d\n",
        _avl_tree_size(&t_tree), _avl_tree_max_size(&t_tree), _avl_tree_empty(&t_tree));
    /*_avl_tree_init_copy_range(*/
    /*&t_tree2, _avl_tree_begin(&t_tree), _avl_tree_begin(&t_tree));*/
    /*printf("avl tree2 - size:%u, max_size:%u, empty:%d\n",*/
    /*_avl_tree_size(&t_tree2), _avl_tree_max_size(&t_tree2), _avl_tree_empty(&t_tree2));*/
    _avl_tree_init_copy_range_cmp(
        &t_tree2, _avl_tree_begin(&t_tree), _avl_tree_begin(&t_tree), NULL);
    printf("avl tree2 - size:%u, max_size:%u, empty:%d\n",
        _avl_tree_size(&t_tree2), _avl_tree_max_size(&t_tree2), _avl_tree_empty(&t_tree2));
    _avl_tree_insert_equal_range(
        &t_tree2, _avl_tree_begin(&t_tree), _avl_tree_begin(&t_tree));
    printf("avl tree2 - size:%u, max_size:%u, empty:%d\n",
        _avl_tree_size(&t_tree2), _avl_tree_max_size(&t_tree2), _avl_tree_empty(&t_tree2));
    _avl_tree_insert_unique_range(
        &t_tree2, _avl_tree_end(&t_tree), _avl_tree_end(&t_tree));
    printf("avl tree2 - size:%u, max_size:%u, empty:%d\n",
        _avl_tree_size(&t_tree2), _avl_tree_max_size(&t_tree2), _avl_tree_empty(&t_tree2));
    _avl_tree_erase_range(&t_tree2, _avl_tree_begin(&t_tree2), _avl_tree_begin(&t_tree2));
    printf("avl tree2 - size:%u, max_size:%u, empty:%d\n",
        _avl_tree_size(&t_tree2), _avl_tree_max_size(&t_tree2), _avl_tree_empty(&t_tree2));

    _avl_tree_destroy(&t_tree);
    _avl_tree_destroy(&t_tree2);
}
Пример #2
0
/**
 * Erase an element from a avl tree that match a specified element.
 */
size_t _avl_tree_erase(_avl_tree_t* pt_avl_tree, const void* cpv_value)
{
    size_t  t_count = _avl_tree_count(pt_avl_tree, cpv_value);
    range_t r_range = _avl_tree_equal_range(pt_avl_tree, cpv_value);

    if (!_avl_tree_iterator_equal(r_range.it_begin, _avl_tree_end(pt_avl_tree))) {
        _avl_tree_erase_range(pt_avl_tree, r_range.it_begin, r_range.it_end);
    }

    return t_count;
}
Пример #3
0
/*
 * Erase a range of element in an set.
 */
void set_erase_range(set_t* pset_set, set_iterator_t it_begin, set_iterator_t it_end)
{
    assert(pset_set != NULL);
    assert(_SET_ITERATOR_CONTAINER_TYPE(it_begin) == _SET_CONTAINER);
    assert(_SET_ITERATOR_ITERATOR_TYPE(it_begin) == _BIDIRECTIONAL_ITERATOR);
    assert(_SET_ITERATOR_CONTAINER_TYPE(it_end) == _SET_CONTAINER);
    assert(_SET_ITERATOR_ITERATOR_TYPE(it_end) == _BIDIRECTIONAL_ITERATOR);
    assert(_SET_ITERATOR_CONTAINER(it_begin) == pset_set);
    assert(_SET_ITERATOR_CONTAINER(it_end) == pset_set);

#ifdef CSTL_SET_AVL_TREE
    _avl_tree_erase_range(&pset_set->_t_tree, it_begin, it_end);
#else
    _rb_tree_erase_range(&pset_set->_t_tree, it_begin, it_end);
#endif
}
Пример #4
0
/*
 * Erase a range of element in an multiset.
 */
void multiset_erase_range(multiset_t* pmset_mset, multiset_iterator_t it_begin, multiset_iterator_t it_end)
{
    assert(pmset_mset != NULL);
    assert(_MULTISET_ITERATOR_CONTAINER_TYPE(it_begin) == _MULTISET_CONTAINER);
    assert(_MULTISET_ITERATOR_ITERATOR_TYPE(it_begin) == _BIDIRECTIONAL_ITERATOR);
    assert(_MULTISET_ITERATOR_CONTAINER_TYPE(it_end) == _MULTISET_CONTAINER);
    assert(_MULTISET_ITERATOR_ITERATOR_TYPE(it_end) == _BIDIRECTIONAL_ITERATOR);
    assert(_MULTISET_ITERATOR_CONTAINER(it_begin) == pmset_mset);
    assert(_MULTISET_ITERATOR_CONTAINER(it_end) == pmset_mset);

#ifdef CSTL_MULTISET_AVL_TREE
    _avl_tree_erase_range(&pmset_mset->_t_tree, it_begin, it_end);
#else
    _rb_tree_erase_range(&pmset_mset->_t_tree, it_begin, it_end);
#endif
}
Пример #5
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
}
Пример #6
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
}