Skip to content

Tree

Inherits: Class

Methods

ChildrenIterator

lua
function Tree:ChildrenIterator(node)
  -> fun():number, table, number

Iterates over all the children of a node.

Parameters:

NameTypeDescription
nodenumberThe node

Returns:

TypeDescription
fun():numberIterator with fields: child
table
number

DepthFirstIterator

lua
function Tree:DepthFirstIterator(rootNode)
  -> fun():number, table

Iterates over the tree in depth-first order.

Parameters:

NameTypeDescription
rootNodenumberThe rootNode to iterate from (defaults to the tree's root node)

Returns:

TypeDescription
fun():numberIterator with fields: node
table

Dump

lua
function Tree:Dump(rootNode)

Prints out the tree for debugging.

Parameters:

NameTypeDescription
rootNodenumberThe root node to dump from

GetChildren

lua
function Tree:GetChildren(node)
  -> ...number

Gets all the children of a node.

Parameters:

NameTypeDescription
nodenumberThe node

Returns:

TypeDescription
...number

GetData

lua
function Tree:GetData(node, fieldName)
  -> ...any

Gets the data stored for the specified node.

Parameters:

NameTypeDescription
nodenumberThe node
fieldNamestringThe name of the field to get

Returns:

TypeDescription
...any

GetDepth

lua
function Tree:GetDepth(node)
  -> number

Gets the depth of a node in the tree.

Parameters:

NameTypeDescription
nodenumber

Returns:

TypeDescription
number

GetNumChildren

lua
function Tree:GetNumChildren(node)
  -> number

Gets the number of children.

Parameters:

NameTypeDescription
nodenumberThe node

Returns:

TypeDescription
number

GetParent

lua
function Tree:GetParent(node)
  -> number?

Gets the parent node.

Parameters:

NameTypeDescription
nodenumber

Returns:

TypeDescription
number?

GetRoot

lua
function Tree:GetRoot()
  -> number

Gets the root node.

Returns:

TypeDescription
number

Insert

lua
function Tree:Insert(parent, ...)
  -> number

Inserts a node into the tree

Parameters:

NameTypeDescription
parentnumberThe parent node
...anyThe data fields for the node

Returns:

TypeDescription
number

MoveUp

lua
function Tree:MoveUp(node)

Moves a node up in the tree, replacing its parent.

Parameters:

NameTypeDescription
nodenumberThe node to move up

RemoveAllChildren

lua
function Tree:RemoveAllChildren(node)

Removes all children for a given node.

Parameters:

NameTypeDescription
nodenumber

SetChildren

lua
function Tree:SetChildren(node, ...)

Sets the children for a given node.

Parameters:

NameTypeDescription
nodenumberThe node
...numberThe new children

SetData

lua
function Tree:SetData(node, fieldName, value)

Sets a data field for a node.

Parameters:

NameTypeDescription
nodenumberThe node
fieldNamestringThe name of the field to set
valueanyThe data field value

Wipe

lua
function Tree:Wipe()

Wipes the tree.

_MoveHelper

lua
function Tree:_MoveHelper(newParent, oldParent, node)

Parameters:

NameTypeDescription
newParent``
oldParent``
node``

_Remove

lua
function Tree:_Remove(node)

Parameters:

NameTypeDescription
node``

Functions

Create

lua
function Tree.Create(...)
  -> Tree

Creates a new tree object.

Parameters:

NameTypeDescription
...stringThe data field names, in order

Returns:

TypeDescription
Tree