Exemplo n.º 1
0
void *avl_node_find(const struct avl_node *node, const void *obj,
                    const struct avl_type_info *info) {
    if (!node)
        return NULL;
    int cmp = info->compare(obj, node->obj);
    if (cmp < 0)
        return avl_node_find(node->left, obj, info);
    if (cmp > 0)
        return avl_node_find(node->right, obj, info);
    return node->obj;
}
Exemplo n.º 2
0
/* find if contains `key` */
static avl_node_t* avl_node_find(avl_node_t* root, avl_key_t key)
{
    if (root == NULL)
        return NULL;
    if (key < root->key)
        return avl_node_find(root->left, key);
    else if (key > root->key)
        return avl_node_find(root->right, key);
    else
        return root;
}
Exemplo n.º 3
0
/* delete data from tree */
int avl_delete(avl_tree_t* tree, avl_key_t key)
{
    /* find before deletion, faster in missed case but slower in hit case */
    if (tree && avl_node_find(tree->root, key))
    {
        tree->root = avl_remove_node(tree->root, key);
        tree->size--;
        return 1;
    }
    return 0;
}
Exemplo n.º 4
0
void *avl_find(const struct avl *tree, const void *obj)
{
    return avl_node_find(tree->root, obj, &tree->type);
}
Exemplo n.º 5
0
/* find if contains `key` */
void* avl_find(avl_tree_t* tree, avl_key_t key)
{
    avl_node_t* node = avl_node_find(tree->root, key);
    return (node != NULL ? node->data : NULL);
}