diff options
author | David Robillard <d@drobilla.net> | 2017-12-16 11:54:40 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2017-12-16 14:00:28 +0100 |
commit | 46b8e6ed53370d76c294c5e40b040ea78d6c9847 (patch) | |
tree | 87b3f6ba6fd93c3f20b9e169443d473b0450f635 /src/zix/btree.c | |
parent | ef7cd1f17eb468b3ac34197a477e6b22516185d4 (diff) | |
download | sord-46b8e6ed53370d76c294c5e40b040ea78d6c9847.tar.gz sord-46b8e6ed53370d76c294c5e40b040ea78d6c9847.tar.bz2 sord-46b8e6ed53370d76c294c5e40b040ea78d6c9847.zip |
Update BTree
Diffstat (limited to 'src/zix/btree.c')
-rw-r--r-- | src/zix/btree.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/zix/btree.c b/src/zix/btree.c index 4557ad4..78a5a0d 100644 --- a/src/zix/btree.c +++ b/src/zix/btree.c @@ -24,7 +24,10 @@ // #define ZIX_BTREE_DEBUG 1 -#define ZIX_BTREE_PAGE_SIZE 4096 +#ifndef ZIX_BTREE_PAGE_SIZE +# define ZIX_BTREE_PAGE_SIZE 4096 +#endif + #define ZIX_BTREE_NODE_SPACE (ZIX_BTREE_PAGE_SIZE - 2 * sizeof(uint16_t)) #define ZIX_BTREE_LEAF_VALS ((ZIX_BTREE_NODE_SPACE / sizeof(void*)) - 1) #define ZIX_BTREE_INODE_VALS (ZIX_BTREE_LEAF_VALS / 2) @@ -319,12 +322,9 @@ zix_btree_insert(ZixBTree* const t, void* const e) ZIX_PRIVATE ZixBTreeIter* zix_btree_iter_new(const ZixBTree* const t) { - const size_t s = t->height * sizeof(ZixBTreeIterFrame); - ZixBTreeIter* const i = (ZixBTreeIter*)malloc(sizeof(ZixBTreeIter) + s); - if (i) { - i->level = 0; - } - return i; + const size_t s = t->height * sizeof(ZixBTreeIterFrame); + + return (ZixBTreeIter*)calloc(1, sizeof(ZixBTreeIter) + s); } ZIX_PRIVATE void @@ -641,6 +641,7 @@ zix_btree_lower_bound(const ZixBTree* const t, } const ZixBTreeIterFrame* const frame = &(*ti)->stack[(*ti)->level]; + assert(frame->node); if (frame->index == frame->node->n_vals) { if (found) { // Found on a previous level but went too far @@ -658,6 +659,7 @@ ZIX_API void* zix_btree_get(const ZixBTreeIter* const ti) { const ZixBTreeIterFrame* const frame = &ti->stack[ti->level]; + assert(frame->node); assert(frame->index < frame->node->n_vals); return frame->node->vals[frame->index]; } |