Meant for very large tree-sets, yea? This tree is aimed at implementing an idea that the depth of a tree can be known from the root-node without a breadth-first or depth-first search.
Every time a node is updated on the tree, it increases the depth-count of its parent, which also increases the depth count of its parent in a recursive manner, so the depth
of the entire tree is always known from the root-node.
Ofcourse, this is only a prototype, and i'll be happy to accept notes on improving the algorithm.
- For now, nodes are only added and not removed.
- The Nodes could extend the array prototyping instead of having the property
children
which could be manipulated, thus defeating the purpose.
Fixed bug pointed out by @blaise-zaga where adding another child node to a node with an existing child would still update depth and increment it.
Fix: No more incrementation ...
depth
updates usingMath.max
instead