New in version 2.5.
Like Tree but with cyclic s Abjad data structure to work with a sequence whose elements have been grouped into arbitrarily many levels of cyclic containment.
Exactly like the Tree class but with the additional affordance that all integer indices of any size work at every level of structure; like CyclicTuple, CyclicList and CyclicMatrix, no index errors raises in working with objects of this class.
abjad> from abjad.tools import sequencetools
Here is a cyclic tree:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> cyclic_tree = sequencetools.CyclicTree(sequence)
abjad> cyclic_tree
CyclicTree([[0, 1], [2, 3], [4, 5], [6, 7]])
Here’s an internal node:
abjad> cyclic_tree[2]
CyclicTree([4, 5])
Here’s the same node indexed with a different way:
abjad> cyclic_tree[2]
CyclicTree([4, 5])
With a negative index:
abjad> cyclic_tree[-2]
CyclicTree([4, 5])
And another negative index:
abjad> cyclic_tree[-6]
CyclicTree([4, 5])
Here’s a leaf node:
abjad> cyclic_tree[2][0]
CyclicTree(4)
And here’s the same node indexed a different way:
abjad> cyclic_tree[2][20]
CyclicTree(4)
All other interface attributes function as in Tree.
New in version 2.4.
Children of node:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].children
(Tree(2), Tree(3))
Return tuple of zero or more nodes.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Depth of subtree:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].depth
2
Return nonnegative integer.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Improper parentage of node:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].improper_parentage
(Tree([2, 3]), Tree([[0, 1], [2, 3], [4, 5], [6, 7]]))
Return tuple of one or more nodes.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Index of node in parent:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].index_in_parent
1
Return nonnegative integer.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Level of node:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].level
1
Return nonnegative integer.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Negative level of node:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].negative_level
-2
Return negative integer.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Position of node relative to root:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].position
(1,)
Return tuple of zero or more nonnegative integers.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Proper parentage of node:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].proper_parentage
(Tree([[0, 1], [2, 3], [4, 5], [6, 7]]),)
Return tuple of zero or more nodes.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Root of tree:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].proper_parentage
(Tree([[0, 1], [2, 3], [4, 5], [6, 7]]),)
Return node.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Number of leaves in subtree:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].width
2
Return nonnegative integer.
Note
Inherited from sequencetools.Tree
New in version 2.5.
Get next n complete nodes at level from node.
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
With nonnegative level:
Get next 4 nodes at level 2:
abjad> tree[0][0].get_next_n_complete_nodes_at_level(4, 2)
[Tree(1), Tree(2), Tree(3), Tree(4)]
Get next 3 nodes at level 1:
abjad> tree[0][0].get_next_n_complete_nodes_at_level(3, 1)
[Tree([1]), Tree([2, 3]), Tree([4, 5]), Tree([6, 7])]
With negative level:
Get next 4 nodes at level -1:
abjad> tree[0][0].get_next_n_complete_nodes_at_level(4, -1)
[Tree(1), Tree(2), Tree(3), Tree(4)]
Get next 3 nodes at level -2:
abjad> tree[0][0].get_next_n_complete_nodes_at_level(3, -2)
[Tree([1]), Tree([2, 3]), Tree([4, 5]), Tree([6, 7])]
Trim first node if necessary.
Return list of nodes.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Get next n nodes at level from node.
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
With nonnegative level:
Get next 4 nodes at level 2:
abjad> tree[0][0].get_next_n_nodes_at_level(4, 2)
[Tree(1), Tree(2), Tree(3), Tree(4)]
Get next 3 nodes at level 1:
abjad> tree[0][0].get_next_n_nodes_at_level(3, 1)
[Tree([1]), Tree([2, 3]), Tree([4, 5])]
Get next node at level 0:
abjad> tree[0][0].get_next_n_nodes_at_level(1, 0)
[Tree([[1], [2, 3], [4, 5], [6, 7]])]
With negative level:
Get next 4 nodes at level -1:
abjad> tree[0][0].get_next_n_nodes_at_level(4, -1)
[Tree(1), Tree(2), Tree(3), Tree(4)]
Get next 3 nodes at level -2:
abjad> tree[0][0].get_next_n_nodes_at_level(3, -2)
[Tree([1]), Tree([2, 3]), Tree([4, 5])]
Trim first node if necessary.
Return list of nodes.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Get node at position:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree.get_node_at_position((2, 1))
Tree(5)
Return node.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Get position of descendent relative to node rather than relative to root:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[3].get_position_of_descendant(tree[3][0])
(0,)
Return tuple of zero or more nonnegative integers.
Note
Inherited from sequencetools.Tree
New in version 2.4.
True when node is at level in tree:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1][1].is_at_level(-1)
True
False otherwise:
abjad> tree[1][1].is_at_level(0)
False
Return boolean.
Predicate works for positive, negative and zero-valued level.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Iterate depth at level:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> for x in tree.iterate_at_level(0): x
...
Tree([[0, 1], [2, 3], [4, 5], [6, 7]])
abjad> for x in tree.iterate_at_level(1): x
...
Tree([0, 1])
Tree([2, 3])
Tree([4, 5])
Tree([6, 7])
abjad> for x in tree.iterate_at_level(2): x
...
Tree(0)
Tree(1)
Tree(2)
Tree(3)
Tree(4)
Tree(5)
Tree(6)
Tree(7)
abjad> for x in tree.iterate_at_level(-1): x
...
Tree(0)
Tree(1)
Tree(2)
Tree(3)
Tree(4)
Tree(5)
Tree(6)
Tree(7)
abjad> for x in tree.iterate_at_level(-2): x
...
Tree([0, 1])
Tree([2, 3])
Tree([4, 5])
Tree([6, 7])
abjad> for x in tree.iterate_at_level(-3): x
...
Tree([[0, 1], [2, 3], [4, 5], [6, 7]])
Return node generator.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Iterate tree depth-first:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> for node in tree.iterate_depth_first(): node
...
Tree([[0, 1], [2, 3], [4, 5], [6, 7]])
Tree([0, 1])
Tree(0)
Tree(1)
Tree([2, 3])
Tree(2)
Tree(3)
Tree([4, 5])
Tree(4)
Tree(5)
Tree([6, 7])
Tree(6)
Tree(7)
Return node generator.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Iterate tree payload:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> for element in tree.iterate_payload():
... element
...
0
1
2
3
4
5
6
7
Return payload generator.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Remove node from tree:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree.remove(tree[1])
abjad> tree
Tree([[0, 1], [4, 5], [6, 7]])
Return none.
Note
Inherited from sequencetools.Tree
New in version 2.4.
Remove node and all nodes left of node to root:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[0][0].remove_to_root()
abjad> tree
Tree([[1], [2, 3], [4, 5], [6, 7]])
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[0][1].remove_to_root()
abjad> tree
Tree([[2, 3], [4, 5], [6, 7]])
abjad> tree = sequencetools.Tree(sequence)
abjad> tree[1].remove_to_root()
abjad> tree
Tree([[4, 5], [6, 7]])
Modify in-place to root.
Return none.
Note
Inherited from sequencetools.Tree
New in version 2.5.
Change tree to nested lists:
abjad> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
abjad> tree = sequencetools.Tree(sequence)
abjad> tree
Tree([[0, 1], [2, 3], [4, 5], [6, 7]])
abjad> tree.to_nested_lists()
[[0, 1], [2, 3], [4, 5], [6, 7]]
Return list of lists.
Note
Inherited from sequencetools.Tree
Note
Inherited from sequencetools.Tree
x.__delattr__(‘name’) <==> del x.name
Note
Inherited from __builtin__.object
Note
Inherited from sequencetools.Tree
Abjad objects by default do not implement this method.
Raise exception.
Note
Inherited from abctools.AbjadObject
Note
Inherited from sequencetools.Tree
Abjad objects by default do not implement this method.
Raise exception
Note
Inherited from abctools.AbjadObject
Note
Inherited from __builtin__.object
Abjad objects by default do not implement this method.
Raise exception.
Note
Inherited from abctools.AbjadObject
Note
Inherited from sequencetools.Tree
Abjad objects by default do not implement this method.
Raise exception.
Note
Inherited from abctools.AbjadObject
Note
Inherited from sequencetools.Tree
Note
Inherited from sequencetools.Tree
x.__setattr__(‘name’, value) <==> x.name = value
Note
Inherited from __builtin__.object
Note
Inherited from sequencetools.Tree