dreamworkAPI
Ctrl K
GitHub
classDocs / Node

Node

classsharedmenusource
Object → Node

A node in a generic tree structure.

Each node holds an arbitrary value, an optional parent link, and a list of child nodes (stored in the node's array part, sized by width).

Nodes track their own depth (distance from the root) and expose helpers to link/unlink from a parent, traverse the subtree, and measure its size.

Constructor

Node(value: T, parent: ( Node<T> | nil )): Node<T>

Fields

NameTypeDescription
valueTThe value stored in the node.
parent?Node<T>The parent node, or nil if this node is a root (not currently linked to anything).
depthnumberHow many links deep this node is from its root (root has depth 0).
widthnumberThe number of direct children this node has.

Methods

linkLinks this node to a parent node, appending it to the parent's child list and updating this node's depth to parent.dept…
sizeReturns the size of the node tree.
traverseWalks this node and every descendant in depth-first, parent-before-child order, calling callback once for each node vis…
unlinkUnlinks this node from its parent, removing it from the parent's child list and resetting this node's depth to 0.

#Node:size

sharedmenunodiscardsource
function Node:size(): integer

Returns the size of the node tree.

Returns
TypeNameDescription
integersizeThe size of the node tree.

#Node:traverse

sharedmenusource
function Node:traverse(callback: fun( node: Node<T> ))

Walks this node and every descendant in depth-first, parent-before-child order, calling callback once for each node visited.

Parameters
NameTypeDescription
callbackfun( node: Node<T> )The callback invoked for each node in the subtree.
Generated from the dreamwork meta branch.