aboutsummaryrefslogtreecommitdiffstats
path: root/src/zix/btree.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-12 13:28:47 +0200
committerDavid Robillard <d@drobilla.net>2018-11-25 22:12:48 +0100
commitc9fe9fdb61e15b64d03a8da062648ecd3f86d700 (patch)
tree4c2f6a751aed6a8abe03ef0b65bcbf675bf6bda8 /src/zix/btree.c
parent06f860fd95ba9f97e36416ad8fa3cdadba4f6259 (diff)
downloadserd-c9fe9fdb61e15b64d03a8da062648ecd3f86d700.tar.gz
serd-c9fe9fdb61e15b64d03a8da062648ecd3f86d700.tar.bz2
serd-c9fe9fdb61e15b64d03a8da062648ecd3f86d700.zip
WIP: Add model
Diffstat (limited to 'src/zix/btree.c')
-rw-r--r--src/zix/btree.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/zix/btree.c b/src/zix/btree.c
index 7521086d..a55c4699 100644
--- a/src/zix/btree.c
+++ b/src/zix/btree.c
@@ -55,6 +55,7 @@ typedef struct {
} ZixBTreeIterFrame;
struct ZixBTreeIterImpl {
+ unsigned n_levels; ///< Maximum depth of stack
unsigned level; ///< Current level in stack
ZixBTreeIterFrame stack[]; ///< Position stack
};
@@ -350,7 +351,9 @@ zix_btree_iter_new(const ZixBTree* const t)
{
const size_t s = t->height * sizeof(ZixBTreeIterFrame);
- return (ZixBTreeIter*)calloc(1, sizeof(ZixBTreeIter) + s);
+ ZixBTreeIter* i = (ZixBTreeIter*)calloc(1, sizeof(ZixBTreeIter) + s);
+ i->n_levels = t->height;
+ return i;
}
ZIX_PRIVATE void
@@ -712,12 +715,47 @@ zix_btree_begin(const ZixBTree* const t)
return i;
}
+ZIX_API ZixBTreeIter*
+zix_btree_end(const ZixBTree* const t)
+{
+ return zix_btree_iter_new(t);
+}
+
+ZIX_API ZixBTreeIter*
+zix_btree_iter_copy(const ZixBTreeIter* const i)
+{
+ if (!i) {
+ return NULL;
+ }
+
+ const size_t s = i->n_levels * sizeof(ZixBTreeIterFrame);
+
+ ZixBTreeIter* j = (ZixBTreeIter*)malloc(sizeof(ZixBTreeIter) + s);
+ memcpy(j, i, sizeof(ZixBTreeIter) + s);
+ return j;
+}
+
ZIX_API bool
zix_btree_iter_is_end(const ZixBTreeIter* const i)
{
return !i || i->stack[0].node == NULL;
}
+ZIX_API bool
+zix_btree_iter_equals(const ZixBTreeIter* const lhs, const ZixBTreeIter* const rhs)
+{
+ if (zix_btree_iter_is_end(lhs) && zix_btree_iter_is_end(rhs)) {
+ return true;
+ } else if (!lhs || !rhs || lhs->n_levels != rhs->n_levels) {
+ return false;
+ }
+
+ return !memcmp(lhs,
+ rhs,
+ sizeof(ZixBTreeIter) +
+ lhs->n_levels * sizeof(ZixBTreeIterFrame));
+}
+
ZIX_API void
zix_btree_iter_increment(ZixBTreeIter* const i)
{