From 129bcfb52322c2e27fc0e63605bc04c99ac40f8c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 10 Sep 2021 20:11:33 -0400 Subject: 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. --- include/zix/btree.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'include') 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 -- cgit v1.2.1