rbtree: add rbt_destroy
This function will free all the nodes inside the red-black tree. It is still on the caller to free the struct rbtree that they passed into the function if it was dynamically allocated
This commit is contained in:
parent
b84a48aaa7
commit
408f00bb05
1 changed files with 11 additions and 1 deletions
12
lib/rbtree.c
12
lib/rbtree.c
|
|
@ -272,6 +272,17 @@ void rbt_delete(struct rbtree *tree, struct rbnode *del)
|
|||
}
|
||||
}
|
||||
|
||||
void rbt_destroy(struct rbtree *tree, struct rbnode *node)
|
||||
{
|
||||
if (node == NULL)
|
||||
return;
|
||||
|
||||
rbt_destroy(tree, node->left);
|
||||
rbt_destroy(tree, node->right);
|
||||
|
||||
rbt_delete(tree, node);
|
||||
}
|
||||
|
||||
struct rbnode *rbt_search(struct rbtree *tree, uint64_t key)
|
||||
{
|
||||
struct rbnode *node = tree->root;
|
||||
|
|
@ -288,4 +299,3 @@ struct rbnode *rbt_search(struct rbtree *tree, uint64_t key)
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue