diff options
author | David Robillard <d@drobilla.net> | 2011-09-05 15:56:02 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-09-05 15:56:02 +0000 |
commit | 9c129fa5ca61da479507d2598951f3fdacc1e143 (patch) | |
tree | c554b3df4a781bf4ea2fc39abea75862b0f6ad19 /src | |
parent | a54b3fcd7b73411f9decc82ebf7ddb906e13052b (diff) | |
download | zix-9c129fa5ca61da479507d2598951f3fdacc1e143.tar.gz zix-9c129fa5ca61da479507d2598951f3fdacc1e143.tar.bz2 zix-9c129fa5ca61da479507d2598951f3fdacc1e143.zip |
Separate tree functions into a separate header. Add tree iterator functions.
git-svn-id: http://svn.drobilla.net/zix/trunk@2 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
Diffstat (limited to 'src')
-rw-r--r-- | src/tree.c | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -722,3 +722,56 @@ zix_tree_get_data(ZixTreeIter ti) { return ti->data; } + +ZIX_API +ZixTreeIter +zix_tree_begin(ZixTree* t) +{ + if (!t->root) { + return NULL; + } + + ZixTreeNode* n = t->root; + while (n->left) { + n = n->left; + } + return n; +} + +ZIX_API +ZixTreeIter +zix_tree_end(ZixTree* t) +{ + return NULL; +} + +ZIX_API +bool +zix_tree_iter_is_end(ZixTreeIter i) +{ + return !i; +} + +ZIX_API +ZixTreeIter +zix_tree_iter_next(ZixTreeIter i) +{ + if (!i) { + return NULL; + } + + if (i->right) { + i = i->right; + while (i->left) { + i = i->left; + } + } else { + while (i->parent && i->parent->right == i) { // i is a right child + i = i->parent; + } + + i = i->parent; + } + + return i; +} |