Breadth-first iteration of the children of node
Iterate over direct children of root
, yielding TreeNode instances.
Use childrenValues to iterate over child values
Compares two nodes.
Computes the maximum depth of the tree.
That is, how many steps down from node
it can go.
If a tree is: root -> childA -> subChildB
Creates a TreeNode
instance with a given value and parent.
Parent node, if specified, has its childrenStore
property changed to include new child.
Depth-first iteration of the children of node
Returns the first immediate child of parent
that matches value
.
Returns the first parent that has a given value.
Returns true if prospectiveChild
is some child node of parent
,
anywhere in the tree structure.
Returns true if prospectiveParent
is any ancestor
parent of child
.
Returns true if prospectiveParent
is the immediate
parent of child
.
Returns the depth of node
. A root node (ie. with no parents) has a depth of 0.
Iterate over all parents of root
. First result is the immediate parent.
Yields the node value of each parent of child
.
undefined values are not returned.
Yield all immediate children of parent
that match value
.
Yields all parents of child
that have a given value.
Use findParentsValue to find the first match only.
Removes child
from the tree structure it is in.
It removes child
from its parent. Any sub-children of child
still remain connected.
Creates the root for a tree, with an optional value
.
Use rootWrapped if you want a more object-oriented mode of access.
Creates a tree, returning it as a WrappedNode for object-oriented access. Use root alternatively.
Converts TreeNode
to SimplifiedNode
, removing the 'parent' fields.
This can be useful because if you have the whole tree, the parent field
is redundant and because it makes circular references can make dumping to console etc more troublesome.
Throws an exception if root
fails tree validation
Validates the tree from root
downwards.
Wraps node n
for a more object-oriented means of access.
It will wrap child nodes on demand. For this reason, WrappedNode object
identity is not stable
Projects
node
as a dynamic traversable. Dynamic in the sense that it creates the traversable project for nodes on demand. A consequence is that node identities are not stable.