Package jazzparser :: Package misc :: Package tree :: Module datastructs :: Class ImmutableTree
[hide private]
[frames] | no frames]

Class ImmutableTree

source code

object --+    
         |    
  BaseTree --+
             |
            ImmutableTree

Tree data structure. This is immutable and assumes that the data structure will never be changed. Don't try to change it, as this will violate key assumptions. Instead, convert to a mutable tree.

Immutability is not enforced at all, just assumed.

The advantage of using this over the mutable tree is that certain things, like postorder numbers, can be precomputed, since we know the graph won't change.

Instance Methods [hide private]
 
__init__(self, root)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
mutable(self)
Get a mutable version of the graph.
source code
 
immutable(self) source code
 
postorder(self)
Returns a postorder list of all the nodes in this node's subtree, including itself.
source code
 
postorder_index(self, node)
Returns the index of this node in the tree according to a postorder ordering.
source code
 
descendents(self, node)
ImmutableTree can precompute the descendents of every node, because we know they won't change.
source code

Inherited from BaseTree: __eq__, __getitem__, __len__, __repr__, __str__, can_embed_subtree, copy, find_parent, replace_node, unordered_equal

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, root)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

postorder(self)

source code 

Returns a postorder list of all the nodes in this node's subtree, including itself.

Overrides: BaseTree.postorder
(inherited documentation)

postorder_index(self, node)

source code 

Returns the index of this node in the tree according to a postorder ordering. This is inefficient, because it has to recompute the postorder every time. It is more efficient on ImmutableTree, because it can precompute the postorder.

Note that it is looking for a node by identity, not equality.

Raises:
  • ValueError - if the node is not found in the graph.
Overrides: BaseTree.postorder_index
(inherited documentation)