A helper class for building tree structures
The class manages two pointers: A "vertical" pointer and a "horizontal" pointer.
The vertical pointer moves up and down the tree using the node's TreeNode.parent
field, while the horizontal pointer moves left/right over the children using the TreeNode.prev
and TreeNode.next
fields.
Constructor
Methods
appendChild (val:T):TreeNode<T>
Appends a child node storing val
to the children of the vertical pointer.
inlinechildEnd ():Bool
Moves the horizontal pointer to the first child of the node referenced by the vertical pointer.
Returns:
true if the horizontal pointer was updated or false if there are no children.
inlinechildStart ():Bool
Moves the horizontal pointer to the first child of the node referenced by the vertical pointer.
Returns:
true if the horizontal pointer was updated or false if there are no children.
inlinedown ():Bool
Moves the vertical pointer one level down, so it points to the first child.
Returns:
true if the vertical pointer was updated or false if the node has no children.
free ():Void
Destroys this object by explicitly nullifying all pointers for GC'ing used resources.
Improves GC efficiency/performance (optional).
inlinegetChildNode ():TreeNode<T>
Returns the child node that the tree builder is currently pointing at or null if invalid.
inlinegetNode ():TreeNode<T>
Returns the node that the tree builder is currently pointing at or null if invalid.
inlinegetVal ():T
Returns the data stored in the node that the tree builder is currently pointing at.
insertAfterChild (val:T):TreeNode<T>
Appends a child node storing val
to the node referenced by the vertical pointer.
insertBeforeChild (val:T):TreeNode<T>
Prepends a child node storing val
to the child node referenced by the horizontal pointer.
inlinenextChild ():Bool
Moves the horizontal pointer to the next child.
Returns:
true if the horizontal pointer was updated or false if there is no next child.
prependChild (val:T):TreeNode<T>
Prepends a child node storing val
to the children of the vertical pointer.
inlineprevChild ():Bool
Moves the horizontal pointer to the previous child.
Returns:
true if the horizontal pointer was updated or false if there is no previous child.
removeChild ():Bool
Removes the child node referenced by the horizontal pointer and moves the horizontal pointer to the next child.
Returns:
true if the child node was successfully removed.
inlinesetVal (val:T):TreeBuilder<T>
Stores val
in the node that the tree builder is currently pointing at.
inlineup ():Bool
Moves the vertical pointer one level up.
Returns:
true if the vertical pointer was updated or false if the node has no parent.