TreeNode

class datastructuretools.TreeNode(name=None)

Tree node.

>>> import abjad

Node in a generalized tree.

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" [color=3, group=2, label=TreeContainer, shape=box]; "abjad.tools.datastructuretools.TreeNode.TreeNode" [color=black, fontcolor=white, group=2, label=<<B>TreeNode</B>>, shape=box, style="filled, rounded"]; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.datastructuretools.TreeContainer.TreeContainer"; } subgraph cluster_documentationtools { graph [label=documentationtools]; "abjad.tools.documentationtools.ReSTAutosummaryItem.ReSTAutosummaryItem" [color=4, group=3, label=ReSTAutosummaryItem, shape=box]; "abjad.tools.documentationtools.ReSTDirective.ReSTDirective" [color=4, group=3, label=" ", shape=invis, style=transparent]; "abjad.tools.documentationtools.ReSTDocument.ReSTDocument" [color=4, group=3, label=" ", shape=invis, style=transparent]; "abjad.tools.documentationtools.ReSTHeading.ReSTHeading" [color=4, group=3, label=ReSTHeading, shape=box]; "abjad.tools.documentationtools.ReSTHorizontalRule.ReSTHorizontalRule" [color=4, group=3, label=ReSTHorizontalRule, shape=box]; "abjad.tools.documentationtools.ReSTParagraph.ReSTParagraph" [color=4, group=3, label=ReSTParagraph, shape=box]; "abjad.tools.documentationtools.ReSTTOCItem.ReSTTOCItem" [color=4, group=3, label=ReSTTOCItem, shape=box]; } subgraph cluster_graphtools { graph [label=graphtools]; "abjad.tools.graphtools.GraphvizField.GraphvizField" [color=5, group=4, label=GraphvizField, shape=box]; "abjad.tools.graphtools.GraphvizGraph.GraphvizGraph" [color=5, group=4, label=" ", shape=invis, style=transparent]; "abjad.tools.graphtools.GraphvizGroup.GraphvizGroup" [color=5, group=4, label=" ", shape=invis, style=transparent]; "abjad.tools.graphtools.GraphvizNode.GraphvizNode" [color=5, group=4, label=" ", shape=invis, style=transparent]; "abjad.tools.graphtools.GraphvizTable.GraphvizTable" [color=5, group=4, label=" ", shape=invis, style=transparent]; "abjad.tools.graphtools.GraphvizTableCell.GraphvizTableCell" [color=5, group=4, label=GraphvizTableCell, shape=box]; "abjad.tools.graphtools.GraphvizTableHorizontalRule.GraphvizTableHorizontalRule" [color=5, group=4, label=GraphvizTableHorizontalRule, shape=box]; "abjad.tools.graphtools.GraphvizTableRow.GraphvizTableRow" [color=5, group=4, label=" ", shape=invis, style=transparent]; "abjad.tools.graphtools.GraphvizTableVerticalRule.GraphvizTableVerticalRule" [color=5, group=4, label=GraphvizTableVerticalRule, shape=box]; } subgraph cluster_quantizationtools { graph [label=quantizationtools]; "abjad.tools.quantizationtools.QGridLeaf.QGridLeaf" [color=6, group=5, label=QGridLeaf, shape=box]; } subgraph cluster_rhythmtreetools { graph [label=rhythmtreetools]; "abjad.tools.rhythmtreetools.RhythmTreeContainer.RhythmTreeContainer" [color=7, group=6, label=" ", shape=invis, style=transparent]; "abjad.tools.rhythmtreetools.RhythmTreeLeaf.RhythmTreeLeaf" [color=7, group=6, label=RhythmTreeLeaf, shape=box]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.datastructuretools.TreeNode.TreeNode"; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" -> "abjad.tools.documentationtools.ReSTDirective.ReSTDirective"; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" -> "abjad.tools.documentationtools.ReSTDocument.ReSTDocument"; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" -> "abjad.tools.graphtools.GraphvizGraph.GraphvizGraph"; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" -> "abjad.tools.graphtools.GraphvizGroup.GraphvizGroup"; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" -> "abjad.tools.graphtools.GraphvizNode.GraphvizNode"; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" -> "abjad.tools.graphtools.GraphvizTable.GraphvizTable"; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" -> "abjad.tools.graphtools.GraphvizTableRow.GraphvizTableRow"; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" -> "abjad.tools.rhythmtreetools.RhythmTreeContainer.RhythmTreeContainer"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.documentationtools.ReSTAutosummaryItem.ReSTAutosummaryItem"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.documentationtools.ReSTHeading.ReSTHeading"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.documentationtools.ReSTHorizontalRule.ReSTHorizontalRule"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.documentationtools.ReSTParagraph.ReSTParagraph"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.documentationtools.ReSTTOCItem.ReSTTOCItem"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.graphtools.GraphvizField.GraphvizField"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.graphtools.GraphvizTableCell.GraphvizTableCell"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.graphtools.GraphvizTableHorizontalRule.GraphvizTableHorizontalRule"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.graphtools.GraphvizTableVerticalRule.GraphvizTableVerticalRule"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.quantizationtools.QGridLeaf.QGridLeaf"; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.rhythmtreetools.RhythmTreeLeaf.RhythmTreeLeaf"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

depth The depth of a node in a rhythm-tree structure.
depthwise_inventory A dictionary of all nodes in a rhythm-tree, organized by their depth relative the root node.
graph_order Graph order of tree node.
improper_parentage The improper parentage of a node in a rhythm-tree, being the sequence of node beginning with itself and ending with the root node of the tree.
name Named of tree node.
parent Parent of tree node.
proper_parentage The proper parentage of a node in a rhythm-tree, being the sequence of node beginning with the node’s immediate parent and ending with the root node of the tree.
root The root node of the tree: that node in the tree which has no parent.
__copy__() Copies tree node.
__eq__(argument) Is true when ID of argument equals ID of Abjad object.
__format__([format_specification]) Formats Abjad object.
__hash__() Hashes Abjad object.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.

Read-only properties

TreeNode.depth

The depth of a node in a rhythm-tree structure.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.depth
0
>>> a[0].depth
1
>>> a[0][0].depth
2

Returns int.

TreeNode.depthwise_inventory

A dictionary of all nodes in a rhythm-tree, organized by their depth relative the root node.

>>> a = abjad.TreeContainer(name='a')
>>> b = abjad.TreeContainer(name='b')
>>> c = abjad.TreeContainer(name='c')
>>> d = abjad.TreeContainer(name='d')
>>> e = abjad.TreeContainer(name='e')
>>> f = abjad.TreeContainer(name='f')
>>> g = abjad.TreeContainer(name='g')
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> c.extend([f, g])
>>> inventory = a.depthwise_inventory
>>> for depth in sorted(inventory):
...     print('DEPTH: {}'.format(depth))
...     for node in inventory[depth]:
...         print(node.name)
...
DEPTH: 0
a
DEPTH: 1
b
c
DEPTH: 2
d
e
f
g

Returns dictionary.

TreeNode.graph_order

Graph order of tree node.

Returns tuple.

TreeNode.improper_parentage

The improper parentage of a node in a rhythm-tree, being the sequence of node beginning with itself and ending with the root node of the tree.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.improper_parentage == (a,)
True
>>> b.improper_parentage == (b, a)
True
>>> c.improper_parentage == (c, b, a)
True

Returns tuple of tree nodes.

TreeNode.parent

Parent of tree node.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.parent is None
True
>>> b.parent is a
True
>>> c.parent is b
True

Returns tree node.

TreeNode.proper_parentage

The proper parentage of a node in a rhythm-tree, being the sequence of node beginning with the node’s immediate parent and ending with the root node of the tree.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.proper_parentage == ()
True
>>> b.proper_parentage == (a,)
True
>>> c.proper_parentage == (b, a)
True

Returns tuple of tree nodes.

TreeNode.root

The root node of the tree: that node in the tree which has no parent.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.root is a
True
>>> b.root is a
True
>>> c.root is a
True

Returns tree node.

Read/write properties

TreeNode.name

Named of tree node.

Returns string.

Special methods

TreeNode.__copy__()

Copies tree node.

(AbjadObject).__eq__(argument)

Is true when ID of argument equals ID of Abjad object. Otherwise false.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

(AbjadObject).__hash__()

Hashes Abjad object.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.