TreeNode

class compas.datastructures.TreeNode[source]

Bases: Data

A node of a tree data structure.

Parameters:
**kwargsdict[str, Any], optional

User-defined attributes of the tree node.

Attributes:
parentcompas.datastructures.TreeNode

The parent node of the tree node.

childrenlist[compas.datastructures.TreeNode]

The children of the tree node.

treecompas.datastructures.Tree

The tree to which the node belongs.

is_rootbool

True if the node is the root node of the tree.

is_leafbool

True if the node is a leaf node of the tree.

is_branchbool

True if the node is a branch node of the tree.

acestorsgenerator[compas.datastructures.TreeNode]

A generator of the acestors of the tree node.

descendantsgenerator[compas.datastructures.TreeNode]

A generator of the descendants of the tree node, using a depth-first preorder traversal.

Methods

add

Add a child node to this node.

from_data

Construct an object of this type from the provided data.

remove

Remove a child node from this node.

traverse

Traverse the tree from this node.

Inherited Methods

ToString

Converts the instance to a string.

copy

Make an independent copy of the data object.

from_json

Construct an object of this type from a JSON file.

from_jsonstring

Construct an object of this type from a JSON string.

sha256

Compute a hash of the data for comparison during version control using the sha256 algorithm.

to_data

Convert an object to its native data representation.

to_json

Convert an object to its native data representation and save it to a JSON file.

to_jsonstring

Convert an object to its native data representation and save it to a JSON string.

validate_data

Validate the data against the object's data schema.