summaryrefslogtreecommitdiffstats
path: root/test/test_btree.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2025-06-07 11:58:06 -0400
committerDavid Robillard <d@drobilla.net>2025-06-07 11:58:06 -0400
commite4cd2ad74eaf230d2e0c2a38e5e9001eca71135a (patch)
tree97378fecd9698188fe21d3db1cae017f6a93ee29 /test/test_btree.c
parentbb785b3daeba8d27116aeeb12be6e5b98539398d (diff)
downloadzix-e4cd2ad74eaf230d2e0c2a38e5e9001eca71135a.tar.gz
zix-e4cd2ad74eaf230d2e0c2a38e5e9001eca71135a.tar.bz2
zix-e4cd2ad74eaf230d2e0c2a38e5e9001eca71135a.zip
Reduce empty BTree memory requirements
Avoid over-allocating the ZixBTree structure, and only allocate a root node when elements are inserted. The over-allocation was to make all allocations use pages (towards disk-backed storage), but since this isn't actually supported at the moment it was just a waste of memory.
Diffstat (limited to 'test/test_btree.c')
-rw-r--r--test/test_btree.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/test_btree.c b/test/test_btree.c
index dd665c7..a87e26e 100644
--- a/test/test_btree.c
+++ b/test/test_btree.c
@@ -101,6 +101,23 @@ destroy(void* const ptr, const void* const user_data)
}
static void
+test_empty(void)
+{
+ ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL);
+ assert(t);
+
+ // Check that reading functions work properly with an empty (rootless) tree
+ const int e = 42;
+ ZixBTreeIter ti = zix_btree_end(t);
+ zix_btree_clear(t, NULL, NULL);
+ assert(!zix_btree_size(t));
+ assert(zix_btree_find(t, &e, &ti) == ZIX_STATUS_NOT_FOUND);
+ assert(!zix_btree_lower_bound(t, int_cmp, NULL, &e, &ti));
+
+ zix_btree_free(t, destroy, NULL);
+}
+
+static void
test_clear(void)
{
ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL);
@@ -576,6 +593,7 @@ main(int argc, char** argv)
return EXIT_FAILURE;
}
+ test_empty();
test_clear();
test_free();
test_iter_comparison();