mode.utils.trees¶
Data structure: Trees.
-
class
mode.utils.trees.Node(data: T, *, root: mode.utils.types.trees.NodeT = None, parent: mode.utils.types.trees.NodeT = None, children: List[mode.utils.types.trees.NodeT[T]] = None)¶ Tree node.
Notes
Nodes have a link to
the
.rootnode (or None if this is the top-most node)the
.parentnode (if this is a child node).a list of children
A Node may have arbitrary
.dataassociated with it, and arbitrary data may also be stored in.children.- Parameters
data (Any) – Data to associate with node.
- Keyword Arguments
-
new(data: T) → mode.utils.types.trees.NodeT¶ Create new node from this node.
-
reattach(parent: mode.utils.types.trees.NodeT[T]) → mode.utils.types.trees.NodeT[T]¶ Attach this node to parent node.
-
detach(parent: mode.utils.types.trees.NodeT[T]) → mode.utils.types.trees.NodeT[T]¶ Detach this node from parent node.
-
add_deduplicate(data: Union[T, mode.utils.types.trees.NodeT[T]]) → None¶
-
add(data: Union[T, mode.utils.types.trees.NodeT[T]]) → None¶ Add node as a child node.
-
discard(data: T) → None¶ Remove node so it’s no longer a child of this node.
-
traverse() → Iterator[mode.utils.types.trees.NodeT[T]]¶ Iterate over the tree in BFS order.
-
walk() → Iterator[mode.utils.types.trees.NodeT[T]]¶ Iterate over hierarchy backwards.
This will yield parent nodes all the way up to the root.
-
as_graph() → mode.utils.types.graphs.DependencyGraphT¶ Convert to
DependencyGraph.
-
property
depth¶
-
property
path¶
-
property
parent¶
-
property
root¶