A series of functions to map a binary tree to a list ported from flat-tree.
With clibs for a local install do
$ clib install arablocks/flat-tree.c --save
or from source:
$ git clone git@github.com:arablocks/flat-tree.c.git
$ cd flat-tree.c
$ make
$ make install ## you may need sudo
or even with ghi:
$ ghi arablocks/flat-tree.c
which simply invokes make install
Build the static library by running:
$ make static
#include <flat-tree/flat-tree.h>
TODO
TODO
Returns an array index for the tree element at the given depth and offset
Returns the index of the parent element in tree
Returns the index of this elements sibling
TODO
TODO
Returns true if the array children[leftChild, rightChild] was set with the indices of this element's children. Otherwise it returns false;
Returns the range (inclusive) the tree root at index spans. For example, tree.spans(3) would return [0, 6]
Returns the left spanning in index in the tree index spans
Returns the right spanning in index in the tree index spans.
Returns how many nodes (including parent nodes) a tree contains
Returns the depth of an element
Returns the relative offset of an element
Returns the number of rull roots. Sets roots[] with all the full roots (subtrees where all nodes have either 2 or 0 children) < index. For example, fullRoots(8) returns [3] since the subtree rooted at 3 spans 0 -> 6 and the tree rooted at 7 has a child located at 9 which is >= 8
Create a stateful tree iterator starting at a given index.
Move the iterator to the next item in the tree. This will increment the iterator offset and increment the index by the iterator factor.
Move the iterator to the previous item in the tree. This will decrement the iterator offset and decrement the index by the iterator factor.
Move the iterator the this specific tree index.
Move the iterator to the current parent index
Move the iterator to the current left child index.
Move the iterator to the current right child index.
Move the iterator to the current left span index.
Move the iterator to the current right span index
Is the iterator at a left sibling?
Is the iterator at a right sibling?
Move the iterator to the current sibling
MIT