diff options
author | David Robillard <d@drobilla.net> | 2021-09-10 20:11:33 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-09-10 20:11:33 -0400 |
commit | 129bcfb52322c2e27fc0e63605bc04c99ac40f8c (patch) | |
tree | 0ca0e82ca1dabe19c06397f785143a8b25ed8447 /include/zix | |
parent | c9e48e055296a19eb6dfcac48495f690ada73087 (diff) | |
download | zix-129bcfb52322c2e27fc0e63605bc04c99ac40f8c.tar.gz zix-129bcfb52322c2e27fc0e63605bc04c99ac40f8c.tar.bz2 zix-129bcfb52322c2e27fc0e63605bc04c99ac40f8c.zip |
Remove destroy field of BTree and add zix_btree_clear()
If this is used, it is only when clearing or freeing a tree. Allowing it to be
given as a parameter directly there is clearer and avoids bloating the tree
itself with information that isn't needed.
Diffstat (limited to 'include/zix')
-rw-r--r-- | include/zix/btree.h | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/include/zix/btree.h b/include/zix/btree.h index bce3068..5472eca 100644 --- a/include/zix/btree.h +++ b/include/zix/btree.h @@ -50,12 +50,27 @@ typedef struct ZixBTreeIterImpl ZixBTreeIter; /// Create a new (empty) B-Tree ZIX_API ZixBTree* -zix_btree_new(ZixComparator cmp, const void* cmp_data, ZixDestroyFunc destroy); +zix_btree_new(ZixComparator cmp, const void* cmp_data); -/// Free `t` +/** + Free `t` and all the nodes it contains. + + @param destroy Function to call once for every value in the tree. This can + be used to free values if they are dynamically allocated. +*/ +ZIX_API +void +zix_btree_free(ZixBTree* t, ZixDestroyFunc destroy); + +/** + Clear everything from `t`, leaving it empty. + + @param destroy Function called exactly once for every value in the tree, + just before that value is removed from the tree. +*/ ZIX_API void -zix_btree_free(ZixBTree* t); +zix_btree_clear(ZixBTree* t, ZixDestroyFunc destroy); /// Return the number of elements in `t` ZIX_PURE_API |