コード例 #1
0
ファイル: cstl_rb_tree_aux.c プロジェクト: reyoung/libcstl
/**
 * Test the type and compare function that saved in the rb tree container is same.
 */
bool_t _rb_tree_same_type_ex(const _rb_tree_t* cpt_first, const _rb_tree_t* cpt_second)
{
    assert(cpt_first != NULL);
    assert(cpt_second != NULL);
    assert(_rb_tree_is_inited(cpt_first) || _rb_tree_is_created(cpt_first));
    assert(_rb_tree_is_inited(cpt_second) || _rb_tree_is_created(cpt_second));

    if(cpt_first == cpt_second)
    {
        return true;
    }

    return (cpt_first->_t_compare == cpt_second->_t_compare) && _rb_tree_same_type(cpt_first, cpt_second);
}
コード例 #2
0
ファイル: cstl_rb_tree_aux.c プロジェクト: reyoung/libcstl
/**
 * Test the type that saved in the rb tree container is same.
 */
bool_t _rb_tree_same_type(const _rb_tree_t* cpt_first, const _rb_tree_t* cpt_second)
{
    assert(cpt_first != NULL);
    assert(cpt_second != NULL);
    assert(_rb_tree_is_inited(cpt_first) || _rb_tree_is_created(cpt_first));
    assert(_rb_tree_is_inited(cpt_second) || _rb_tree_is_created(cpt_second));

    if(cpt_first == cpt_second)
    {
        return true;
    }

    return (cpt_first->_t_typeinfo._t_style == cpt_second->_t_typeinfo._t_style) &&
           (cpt_first->_t_typeinfo._pt_type == cpt_second->_t_typeinfo._pt_type) &&
           _type_is_same(_GET_RB_TREE_TYPE_NAME(cpt_first), _GET_RB_TREE_TYPE_NAME(cpt_second));
}
コード例 #3
0
void test__create_rb_tree_auxiliary__libcstl_builtin(void** state)
{
    _rb_tree_t* pt_rb_tree = malloc(sizeof(_rb_tree_t));
    assert_true(_create_rb_tree_auxiliary(pt_rb_tree, "vector_t<int>"));
    assert_true(_rb_tree_is_created(pt_rb_tree));

    _rb_tree_destroy(pt_rb_tree);
}
コード例 #4
0
void test__create_rb_tree_auxiliary__cstr(void** state)
{
    _rb_tree_t* pt_rb_tree = malloc(sizeof(_rb_tree_t));
    assert_true(_create_rb_tree_auxiliary(pt_rb_tree, "char*"));
    assert_true(_rb_tree_is_created(pt_rb_tree));

    _rb_tree_destroy(pt_rb_tree);
}
コード例 #5
0
void test__create_rb_tree_auxiliary__user_define(void** state)
{
    _rb_tree_t* pt_rb_tree = NULL;

    type_register(_test__create_rb_tree_auxiliary__user_define_t, NULL, NULL, NULL, NULL);

    pt_rb_tree = malloc(sizeof(_rb_tree_t));
    assert_true(_create_rb_tree_auxiliary(pt_rb_tree, "_test__create_rb_tree_auxiliary__user_define_t"));
    assert_true(_rb_tree_is_created(pt_rb_tree));

    _rb_tree_destroy(pt_rb_tree);
}
コード例 #6
0
/**
 * Destroy rb tree container auxiliary function.
 */
void _rb_tree_destroy_auxiliary(_rb_tree_t* pt_rb_tree)
{
    assert(pt_rb_tree != NULL);
    assert(_rb_tree_is_inited(pt_rb_tree) || _rb_tree_is_created(pt_rb_tree));

    /* destroy all elements */
    pt_rb_tree->_t_rbroot._pt_parent = _rb_tree_destroy_subtree(pt_rb_tree, pt_rb_tree->_t_rbroot._pt_parent);
    assert(pt_rb_tree->_t_rbroot._pt_parent == NULL);
    pt_rb_tree->_t_rbroot._pt_left = &pt_rb_tree->_t_rbroot;
    pt_rb_tree->_t_rbroot._pt_right = &pt_rb_tree->_t_rbroot;
    pt_rb_tree->_t_nodecount = 0;

    /* destroy allocator */
    _alloc_destroy(&pt_rb_tree->_t_allocator);

    pt_rb_tree->_t_compare = NULL;
}
コード例 #7
0
ファイル: cstl_rb_tree_aux.c プロジェクト: reyoung/libcstl
/**
 * Destroy the subtree with postorder traverse.
 */
_rbnode_t* _rb_tree_destroy_subtree(_rb_tree_t* pt_rb_tree, _rbnode_t* pt_root)
{
    bool_t b_result = false;

    assert(pt_rb_tree != NULL);
    assert(_rb_tree_is_inited(pt_rb_tree) || _rb_tree_is_created(pt_rb_tree));

    if(pt_root != NULL)
    {
        pt_root->_pt_left = _rb_tree_destroy_subtree(pt_rb_tree, pt_root->_pt_left);
        pt_root->_pt_right = _rb_tree_destroy_subtree(pt_rb_tree, pt_root->_pt_right);

        assert(pt_root->_pt_left == NULL && pt_root->_pt_right == NULL);

        b_result = _GET_RB_TREE_TYPE_SIZE(pt_rb_tree);
        _GET_RB_TREE_TYPE_DESTROY_FUNCTION(pt_rb_tree)(pt_root->_pby_data, &b_result);
        assert(b_result);
        _alloc_deallocate(&pt_rb_tree->_t_allocator, pt_root, _RB_TREE_NODE_SIZE(_GET_RB_TREE_TYPE_SIZE(pt_rb_tree)), 1);
    }

    return NULL;
}
コード例 #8
0
ファイル: cstl_rb_tree_aux.c プロジェクト: reyoung/libcstl
/**
 * Initialize element auxiliary function
 */
void _rb_tree_init_elem_auxiliary(_rb_tree_t* pt_rb_tree, _rbnode_t* pt_node)
{
    assert(pt_rb_tree != NULL);
    assert(pt_node != NULL);
    assert(_rb_tree_is_inited(pt_rb_tree) || _rb_tree_is_created(pt_rb_tree));

    /* initialize new elements */
    if(_GET_RB_TREE_TYPE_STYLE(pt_rb_tree) == _TYPE_CSTL_BUILTIN)
    {
        /* get element type name */
        char s_elemtypename[_TYPE_NAME_SIZE + 1];
        _type_get_elem_typename(_GET_RB_TREE_TYPE_NAME(pt_rb_tree), s_elemtypename);

        _GET_RB_TREE_TYPE_INIT_FUNCTION(pt_rb_tree)(pt_node->_pby_data, s_elemtypename);
    }
    else
    {
        bool_t b_result = _GET_RB_TREE_TYPE_SIZE(pt_rb_tree);
        _GET_RB_TREE_TYPE_INIT_FUNCTION(pt_rb_tree)(pt_node->_pby_data, &b_result);
        assert(b_result);
    }
}