goog.structs.TreeNode<KEY, VALUE>
Provided By | |
---|---|
Extends |
|
Generic tree node data structure with arbitrary number of child nodes.
It is possible to create a dynamic tree structure by overriding
#getParent
and #getChildren
in a subclass. All other getters
will automatically work.
new TreeNode<KEY, VALUE>( key, value )
Parameters |
|
---|
Instance Methods
this.addChild( child ) → void
void
Appends a child node to this node.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
|
this.addChildAt( child, index ) → void
void
Inserts a child node at the given index.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.clone() → goog.structs.TreeNode
goog.structs.TreeNode
Clones a node and returns a new node.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.contains( node ) → boolean
boolean
Tells whether this node is the ancestor of the given node.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.deepClone() → goog.structs.TreeNode
goog.structs.TreeNode
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.forEachChild<THIS>( f, opt_this ) → void
void
Traverses all child nodes.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.forEachDescendant<THIS>( f, opt_this ) → void
void
Traverses all child nodes recursively in preorder.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.getAncestors() → Array<goog.structs.TreeNode<(KEY|null), (VALUE|null)>>
Array<goog.structs.TreeNode<(KEY|null), (VALUE|null)>>
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getChildAt( index ) → (goog.structs.TreeNode<KEY, VALUE>|null)
(goog.structs.TreeNode<KEY, VALUE>|null)
Gets the child node of this node at the given index.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.getChildCount() → number
number
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getChildren() → Array<goog.structs.TreeNode<(KEY|null), (VALUE|null)>>
Array<goog.structs.TreeNode<(KEY|null), (VALUE|null)>>
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getDepth() → number
number
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getKey() → KEY
KEY
this.getNodeByKey( key ) → (goog.structs.TreeNode<KEY, VALUE>|null)
(goog.structs.TreeNode<KEY, VALUE>|null)
Returns a node whose key matches the given one in the hierarchy rooted at this node. The hierarchy is searched using an in-order traversal.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.getParent() → (goog.structs.TreeNode<KEY, VALUE>|null)
(goog.structs.TreeNode<KEY, VALUE>|null)
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getRoot() → goog.structs.TreeNode<(KEY|null), (VALUE|null)>
goog.structs.TreeNode<(KEY|null), (VALUE|null)>
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getSubtreeKeys() → Array<(KEY|null)>
Array<(KEY|null)>
Builds a nested array structure from the node keys in this node's subtree to facilitate testing tree operations that change the hierarchy.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getValue() → VALUE
VALUE
this.isLastChild() → boolean
boolean
Tells if the node is the last child of its parent. This method helps how to connect the tree nodes with lines: L shapes should be used before the last children and |- shapes before the rest. Schematic tree visualization:
Node1 |-Node2 | L-Node3 | |-Node4 | L-Node5 L-Node6
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.isLeaf() → boolean
boolean
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.removeChild( child ) → (goog.structs.TreeNode<KEY, VALUE>|null)
(goog.structs.TreeNode<KEY, VALUE>|null)
Removes the given child node of this node.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.removeChildAt( index ) → (goog.structs.TreeNode<KEY, VALUE>|null)
(goog.structs.TreeNode<KEY, VALUE>|null)
Removes the child node at the given index.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.removeChildren() → void
void
this.replaceChild( newChild, oldChild ) → goog.structs.TreeNode<(KEY|null), (VALUE|null)>
goog.structs.TreeNode<(KEY|null), (VALUE|null)>
Replaces the given child node.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||
Returns |
|
this.replaceChildAt( newChild, index ) → goog.structs.TreeNode<(KEY|null), (VALUE|null)>
goog.structs.TreeNode<(KEY|null), (VALUE|null)>
Replaces a child node at the given index.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||
Returns |
|
this.setParent( parent ) → void
void
Sets the parent node of this node. The callers must ensure that the parent node and only that has this node among its children.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
|
this.traverse<THIS>( f, opt_this ) → void
void
Traverses the subtree with the possibility to skip branches. Starts with this node, and visits the descendant nodes depth-first, in preorder.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
Static Functions
TreeNode.findCommonAncestor<KEY, VALUE>( ...var_args ) → (goog.structs.TreeNode<KEY, VALUE>|null)
(goog.structs.TreeNode<KEY, VALUE>|null)
Finds the deepest common ancestor of the given nodes. The concept of ancestor is not strict in this case, it includes the node itself.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|