Ejemplo n.º 1
0
/**
 * Assign avl tree container.
 */
void _avl_tree_assign(_avl_tree_t* pt_dest, const _avl_tree_t* cpt_src)
{
    assert(pt_dest != NULL);
    assert(cpt_src != NULL);
    assert(_avl_tree_is_inited(pt_dest));
    assert(_avl_tree_is_inited(cpt_src));
    assert(_avl_tree_same_type_ex(pt_dest, cpt_src));

    if (!_avl_tree_equal(pt_dest, cpt_src)) {
        _avl_tree_iterator_t it_iter;
        _avl_tree_iterator_t it_begin;
        _avl_tree_iterator_t it_end;

        /* clear dest avl tree */
        _avl_tree_clear(pt_dest);
        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));
        }
    }
}
Ejemplo n.º 2
0
/**
 * Swap the datas of first avl_tree and second avl_tree.
 */
void _avl_tree_swap(_avl_tree_t* pt_first, _avl_tree_t* pt_second)
{
    _avl_tree_t t_temp;

    assert(pt_first != NULL);
    assert(pt_second != NULL);
    assert(_avl_tree_is_inited(pt_first));
    assert(_avl_tree_is_inited(pt_second));
    assert(_avl_tree_same_type_ex(pt_first, pt_second));

    if (_avl_tree_equal(pt_first, pt_second)) {
        return;
    }

    t_temp = *pt_first;
    *pt_first = *pt_second;
    *pt_second = t_temp;

    if (_avl_tree_empty(pt_first)) {
        pt_first->_t_avlroot._pt_left = &pt_first->_t_avlroot;
        pt_first->_t_avlroot._pt_right = &pt_first->_t_avlroot;
    } else {
        pt_first->_t_avlroot._pt_parent->_pt_parent = &pt_first->_t_avlroot;
    }

    if (_avl_tree_empty(pt_second)) {
        pt_second->_t_avlroot._pt_left = &pt_second->_t_avlroot;
        pt_second->_t_avlroot._pt_right = &pt_second->_t_avlroot;
    } else {
        pt_second->_t_avlroot._pt_parent->_pt_parent = &pt_second->_t_avlroot;
    }
}
Ejemplo n.º 3
0
/**
 * Tests if the two set are equal.
 */
bool_t set_equal(const set_t* cpset_first, const set_t* cpset_second)
{
    assert(cpset_first != NULL);
    assert(cpset_second != NULL);

#ifdef CSTL_SET_AVL_TREE
    return _avl_tree_equal(&cpset_first->_t_tree, &cpset_second->_t_tree);
#else
    return _rb_tree_equal(&cpset_first->_t_tree, &cpset_second->_t_tree);
#endif
}
Ejemplo n.º 4
0
/**
 * Tests if the two map are equal.
 */
bool_t map_equal(const map_t* cpmap_first, const map_t* cpmap_second)
{
    assert(cpmap_first != NULL);
    assert(cpmap_second != NULL);
    assert(_pair_is_inited(&cpmap_first->_pair_temp));
    assert(_pair_is_inited(&cpmap_second->_pair_temp));

    if(cpmap_first->_bfun_keycompare != cpmap_second->_bfun_keycompare)
    {
        return false;
    }
#ifdef CSTL_MAP_AVL_TREE
    return _avl_tree_equal(&cpmap_first->_t_tree, &cpmap_second->_t_tree);
#else
    return _rb_tree_equal(&cpmap_first->_t_tree, &cpmap_second->_t_tree);
#endif
}
Ejemplo n.º 5
0
bool_t multimap_equal(
    const multimap_t* cpt_multimapfirst, const multimap_t* cpt_multimapsecond)
{
    assert(cpt_multimapfirst != NULL && cpt_multimapsecond != NULL);

    /* test pair */
    if(cpt_multimapfirst->_t_pair._t_firsttypesize != 
        cpt_multimapsecond->_t_pair._t_firsttypesize || 
       cpt_multimapfirst->_t_pair._t_secondtypesize != 
        cpt_multimapsecond->_t_pair._t_secondtypesize)
    {
        return false;
    }
    if(strncmp(
        cpt_multimapfirst->_t_pair._sz_firsttypename, 
        cpt_multimapsecond->_t_pair._sz_firsttypename, 
        _ELEM_TYPE_NAME_SIZE) != 0 || 
       strncmp(
        cpt_multimapfirst->_t_pair._sz_secondtypename, 
        cpt_multimapsecond->_t_pair._sz_secondtypename, 
        _ELEM_TYPE_NAME_SIZE) != 0)
    {
        return false;
    }
    if(cpt_multimapfirst->_t_pair._pfun_first_cmp != 
        cpt_multimapsecond->_t_pair._pfun_first_cmp || 
       cpt_multimapfirst->_t_pair._pfun_second_cmp != 
        cpt_multimapsecond->_t_pair._pfun_second_cmp)
    {
        return false;
    }
    /* test tree */
#ifdef CSTL_MULTIMAP_AVL_TREE
    return _avl_tree_equal(
        _GET_MULTIMAP_AVL_TREE(cpt_multimapfirst), 
        _GET_MULTIMAP_AVL_TREE(cpt_multimapsecond));
#else
    return _rb_tree_equal(
        _GET_MULTIMAP_RB_TREE(cpt_multimapfirst), 
        _GET_MULTIMAP_RB_TREE(cpt_multimapsecond));
#endif
}
Ejemplo n.º 6
0
/**
 * Tests if the first avl tree is greater than or equal to the second avl tree.
 */
bool_t _avl_tree_greater_equal(const _avl_tree_t* cpt_first, const _avl_tree_t* cpt_second)
{
    return (_avl_tree_greater(cpt_first, cpt_second) || _avl_tree_equal(cpt_first, cpt_second)) ? true : false;
}
Ejemplo n.º 7
0
/**
 * Tests if the first avl tree is less than or equal to the second avl tree.
 */
bool_t _avl_tree_less_equal(const _avl_tree_t* cpt_first, const _avl_tree_t* cpt_second)
{
    return (_avl_tree_less(cpt_first, cpt_second) || _avl_tree_equal(cpt_first, cpt_second)) ? true : false;
}
Ejemplo n.º 8
0
/**
 * Tests if the two avl tree are not equal.
 */
bool_t _avl_tree_not_equal(const _avl_tree_t* cpt_first, const _avl_tree_t* cpt_second)
{
    return !_avl_tree_equal(cpt_first, cpt_second);
}