Exemplo n.º 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);
}
Exemplo n.º 2
0
/**
 * Initialize avl tree container with specific array and compare function.
 */
void _avl_tree_init_copy_unique_array_ex(_avl_tree_t* pt_dest, const void* cpv_array, size_t t_count, bfun_t t_compare)
{
    assert(pt_dest != NULL);
    assert(_avl_tree_is_created(pt_dest));
    assert(cpv_array != NULL);

    _avl_tree_init(pt_dest, t_compare);
    _avl_tree_insert_unique_array(pt_dest, cpv_array, t_count);
}
Exemplo n.º 3
0
/**
 * Initialize avl tree container with specific array.
 */
void _avl_tree_init_copy_equal_array(_avl_tree_t* pt_dest, const void* cpv_array, size_t t_count)
{
    assert(pt_dest != NULL);
    assert(_avl_tree_is_created(pt_dest));
    assert(cpv_array != NULL);

    _avl_tree_init(pt_dest, NULL);
    _avl_tree_insert_equal_array(pt_dest, cpv_array, t_count);
}
Exemplo n.º 4
0
/**
 * Initialize set container with user define compare function.
 */
void set_init_ex(set_t* pset_set, binary_function_t bfun_compare)
{
    assert(pset_set != NULL);

#ifdef CSTL_SET_AVL_TREE
    _avl_tree_init(&pset_set->_t_tree, bfun_compare);
#else
    _rb_tree_init(&pset_set->_t_tree, bfun_compare);
#endif
}
Exemplo n.º 5
0
/**
 * Initialize set container.
 */
void set_init(set_t* pset_set)
{
    assert(pset_set != NULL);

#ifdef CSTL_SET_AVL_TREE
    _avl_tree_init(&pset_set->_t_tree, NULL);
#else
    _rb_tree_init(&pset_set->_t_tree, NULL);
#endif
}
Exemplo n.º 6
0
/**
 * Initialize multiset container with user define compare function.
 */
void multiset_init_ex(multiset_t* pmset_mset, binary_function_t bfun_compare)
{
    assert(pmset_mset != NULL);

#ifdef CSTL_MULTISET_AVL_TREE
    _avl_tree_init(&pmset_mset->_t_tree, bfun_compare);
#else
    _rb_tree_init(&pmset_mset->_t_tree, bfun_compare);
#endif
}
Exemplo n.º 7
0
/**
 * Initialize multiset container.
 */
void multiset_init(multiset_t* pmset_mset)
{
    assert(pmset_mset != NULL);

#ifdef CSTL_MULTISET_AVL_TREE
    _avl_tree_init(&pmset_mset->_t_tree, NULL);
#else
    _rb_tree_init(&pmset_mset->_t_tree, NULL);
#endif
}
Exemplo n.º 8
0
/**
 * Initialize avl tree container with specific range and compare function.
 */
void _avl_tree_init_copy_unique_range_ex(_avl_tree_t* pt_dest, iterator_t it_begin, iterator_t it_end, bfun_t t_compare)
{
    assert(pt_dest != NULL);
    assert(_avl_tree_is_created(pt_dest));
    assert(_avl_tree_same_iterator_type(pt_dest, it_begin));
    assert(_avl_tree_same_iterator_type(pt_dest, it_end));
    assert(iterator_equal(it_begin, it_end) || _iterator_before(it_begin, it_end));

    _avl_tree_init(pt_dest, t_compare);
    _avl_tree_insert_unique_range(pt_dest, it_begin, it_end);
}
Exemplo n.º 9
0
/**
 * Initialize avl tree container with specific range.
 */
void _avl_tree_init_copy_equal_range(_avl_tree_t* pt_dest, iterator_t it_begin, iterator_t it_end)
{
    assert(pt_dest != NULL);
    assert(_avl_tree_is_created(pt_dest));
    assert(_avl_tree_same_iterator_type(pt_dest, it_begin));
    assert(_avl_tree_same_iterator_type(pt_dest, it_end));
    assert(iterator_equal(it_begin, it_end) || _iterator_before(it_begin, it_end));

    _avl_tree_init(pt_dest, NULL);
    _avl_tree_insert_equal_range(pt_dest, it_begin, it_end);
}
Exemplo n.º 10
0
void test__avl_tree_destroy_auxiliary__non_inited(void** state)
{
    _avl_tree_t* pt_avl_tree = _create_avl_tree("int");
    _avl_tree_init(pt_avl_tree, NULL);

    pt_avl_tree->_t_avlroot._un_height = 9;
    expect_assert_failure(_avl_tree_destroy_auxiliary(pt_avl_tree));
    pt_avl_tree->_t_avlroot._un_height = 0;

    _avl_tree_destroy(pt_avl_tree);
}
Exemplo n.º 11
0
/* map function */
void map_init(map_t* pt_map)
{
    assert(pt_map != NULL);

    /* initialize the pair */
    pair_init(&pt_map->_t_pair);
    /* initialize the tree */
#ifdef CSTL_MAP_AVL_TREE
    _avl_tree_init(_GET_MAP_AVL_TREE(pt_map), _map_cmp, _map_destroy_elem);
#else
    _rb_tree_init(_GET_MAP_RB_TREE(pt_map), _map_cmp, _map_destroy_elem);
#endif
}
Exemplo n.º 12
0
void test__avl_tree_destroy_auxiliary__empty(void** state)
{
    _avl_tree_t* pt_avl_tree = _create_avl_tree("int");
    _avl_tree_init(pt_avl_tree, NULL);

    _avl_tree_destroy_auxiliary(pt_avl_tree);
    assert_true(pt_avl_tree->_t_avlroot._pt_parent == NULL);
    assert_true(pt_avl_tree->_t_avlroot._pt_left == &pt_avl_tree->_t_avlroot);
    assert_true(pt_avl_tree->_t_avlroot._pt_right == &pt_avl_tree->_t_avlroot);
    assert_true(pt_avl_tree->_t_nodecount == 0);
    assert_true(pt_avl_tree->_t_compare == NULL);
    free(pt_avl_tree);
}
Exemplo n.º 13
0
/**
 * Initialize map container.
 */
void map_init(map_t* pmap_map)
{
    assert(pmap_map != NULL);
    assert(_pair_is_created(&pmap_map->_pair_temp));

    /* initialize the pair */
    pair_init(&pmap_map->_pair_temp);
    /* initialize the tree */
#ifdef CSTL_MAP_AVL_TREE
    _avl_tree_init(&pmap_map->_t_tree, _map_value_compare);
#else
    _rb_tree_init(&pmap_map->_t_tree, _map_value_compare);
#endif
}
Exemplo n.º 14
0
/**
 * Initialize map container with user define compare function.
 */
void map_init_ex(map_t* pmap_map, binary_function_t bfun_keycompare)
{
    assert(pmap_map != NULL);
    assert(_pair_is_created(&pmap_map->_pair_temp));

    pair_init(&pmap_map->_pair_temp);
    pmap_map->_bfun_keycompare = bfun_keycompare;
    pmap_map->_pair_temp._bfun_mapkeycompare = bfun_keycompare;

#ifdef CSTL_MAP_AVL_TREE
    _avl_tree_init(&pmap_map->_t_tree, _map_value_compare);
#else
    _rb_tree_init(&pmap_map->_t_tree, _map_value_compare);
#endif
}
Exemplo n.º 15
0
/**
 * Initialize avl tree container with avl tree.
 */
void _avl_tree_init_copy(_avl_tree_t* pt_dest, const _avl_tree_t* cpt_src)
{
    _avl_tree_iterator_t it_iter;
    _avl_tree_iterator_t it_begin;
    _avl_tree_iterator_t it_end;

    assert(pt_dest != NULL);
    assert(cpt_src != NULL);
    assert(_avl_tree_is_created(pt_dest));
    assert(_avl_tree_is_inited(cpt_src));
    assert(_avl_tree_same_type(pt_dest, cpt_src));

    /* init the avl tree with the src avl tree */
    _avl_tree_init(pt_dest,  cpt_src->_t_compare);
    it_begin = _avl_tree_begin(cpt_src);
    it_end = _avl_tree_end(cpt_src);

    /* insert all elements of src into dest */
    for (it_iter = it_begin;
         !_avl_tree_iterator_equal(it_iter, it_end);
         it_iter = _avl_tree_iterator_next(it_iter)) {
        _avl_tree_insert_equal(pt_dest, _avl_tree_iterator_get_pointer_ignore_cstr(it_iter));
    }
}