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

new (node:TreeNode<T>)

Creates a TreeBuilder object pointing to node.

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.

inlinechildValid ():Bool

Returns true if the horizontal pointer is valid.

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.

inlinegetChildVal ():T

Returns the data of the child pointer.

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.

inlinehasNextChild ():Bool

Returns true if the horizontal pointer has a next child.

inlinehasPrevChild ():Bool

Returns true if the horizontal pointer has a previous child.

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.

root ():TreeBuilder<T>

Moves the vertical pointer to the root of the tree.

inlinesetVal (val:T):TreeBuilder<T>

Stores val in the node that the tree builder is currently pointing at.

toString ():String

Prints out all elements.

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.

inlinevalid ():Bool

Returns true if the vertical pointer is valid.