pygsti.layouts.prefixtable.RootNode#
- class RootNode(value, cost=0, tree=None, children=None, orig_indices=None)#
Bases:
TreeNodeClass for representing a root node for a tree, along with the corresponding metadata specific to root nodes.
Initialize a RootNode with a value, optional cost, optional tree, optional children, and optional original indices.
- Parameters:
value (any) – The value to be stored in the node.
cost (int, optional (default is 0)) – The initial cost associated with the root node.
tree (Tree, optional (default is None)) – The tree to which this root node belongs.
children (list, optional (default is None)) – A list of child nodes. If None, initializes an empty list.
orig_indices (list, optional (default is None)) – A list of original indices. If None, initializes an empty list.
Methods
__init__(value[, cost, tree, children, ...])Initialize a RootNode with a value, optional cost, optional tree, optional children, and optional original indices.
add_child(child_node)Add a child node to the current node.
add_orig_index(value)Add an original index to the node.
get_child_node(value)Get the child node associated with the input value.
Get all descendant node values of the current node in pre-order traversal.
print_tree([level, prefix])Print the tree structure starting from the current node.
remove_child(child_node)Remove a child node from the current node.
Calculate the total number of orig_indices values for this node and all of its descendants.
traverse()Traverse the tree in pre-order and return a list of node values.
- add_child(child_node)#
Add a child node to the current node.
- Parameters:
child_node (TreeNode) – The child node to be added.
- add_orig_index(value)#
Add an original index to the node.
- Parameters:
value (int) – The original index to be added.
- get_child_node(value)#
Get the child node associated with the input value. If that node is not present, return None.
- Parameters:
value (any) – The value to search for in the child nodes.
- Returns:
The child node with the specified value, or None if not found.
- Return type:
TreeNode or None
- get_descendants()#
Get all descendant node values of the current node in pre-order traversal.
- Returns:
A list of descendant node values.
- Return type:
list
- print_tree(level=0, prefix='')#
Print the tree structure starting from the current node.
- Parameters:
level (int, optional (default 0)) – The current level in the tree.
prefix (str, optional (default "")) – The prefix for the current level.
- remove_child(child_node)#
Remove a child node from the current node.
- Parameters:
child_node (TreeNode) – The child node to be removed.
- total_orig_indices()#
Calculate the total number of orig_indices values for this node and all of its descendants.
- traverse()#
Traverse the tree in pre-order and return a list of node values.
- Returns:
A list of node values in pre-order traversal.
- Return type:
list