Example #1
0
/**
 * Travel subtree for find the value in preorder.
 */
_avlnode_t* _avl_tree_find_value(const _avl_tree_t* cpt_avl_tree, const _avlnode_t* cpt_root, const void* cpv_value) 
{
    bool_t b_result = false;

    assert(cpt_avl_tree != NULL);
    assert(cpv_value != NULL);
    assert(_avl_tree_is_inited(cpt_avl_tree));

    if (cpt_root == NULL) {
        return NULL;
    }

    b_result = _GET_AVL_TREE_TYPE_SIZE(cpt_avl_tree);
    _avl_tree_elem_compare_auxiliary(cpt_avl_tree, cpv_value, cpt_root->_pby_data, &b_result);
    if (b_result) {
        return _avl_tree_find_value(cpt_avl_tree, cpt_root->_pt_left, cpv_value);
    }

    b_result = _GET_AVL_TREE_TYPE_SIZE(cpt_avl_tree);
    _avl_tree_elem_compare_auxiliary(cpt_avl_tree, cpt_root->_pby_data, cpv_value, &b_result);
    if (b_result) {
        return _avl_tree_find_value(cpt_avl_tree, cpt_root->_pt_right, cpv_value);
    } else {
        return (_avlnode_t*)cpt_root;
    }
}
Example #2
0
/**
 * Find specific element.
 */
_avl_tree_iterator_t _avl_tree_find(const _avl_tree_t* cpt_avl_tree, const void* cpv_value)
{
    _avl_tree_iterator_t it_iter;

    assert(cpt_avl_tree != NULL);
    assert(cpv_value != NULL);
    assert(_avl_tree_is_inited(cpt_avl_tree));

    _AVL_TREE_ITERATOR_TREE_POINTER(it_iter) = (void*)cpt_avl_tree;
    _AVL_TREE_ITERATOR_COREPOS(it_iter) = (_byte_t*)_avl_tree_find_value(
        cpt_avl_tree, cpt_avl_tree->_t_avlroot._pt_parent, cpv_value);
    if (_AVL_TREE_ITERATOR_COREPOS(it_iter) == NULL) {
        _AVL_TREE_ITERATOR_COREPOS(it_iter) = (_byte_t*)&cpt_avl_tree->_t_avlroot;
    }

    return it_iter;
}