Library/Patterns/Tree
From Athile
Defined a data structure of Nodes where each Node has one and exactly one parent, with the single exception of the root of the tree.
Common methods
- insertBefore
- insertAfter
- insertAt
- prepend / shift / push_front - add to the start of the children
- append / push / push_back - add to the end of the children
- promote / moveLeft / moveIn - make a sibling of its current parent
- demote / moveRight/ moveOut - make a child of the prior sibling
- firstSibling - first sibling of the node's parent
- nextSibling - the next child of the current node's parent; possibly null or undefined
- previousSibling - the previous child of the current node's parent; possibly null or undefined
- lastSibling - last sibling of the node's parent
- nextDepthFirst - the next node in the tree as if walking in a depth first, linear fashion
- prevDepthFirst
- nextBreadthFirst - iterate to the next element based on a breadth first search. Implementation: nextSibling, but if undefined then return first child of firstSibling()
- prevBreadthFirst - prevSibling, but if undefined return parent