pygsti.layouts.prefixtable.TreeNode#

class TreeNode(value, children=None, orig_indices=None)#

Bases: object

Parameters:
  • value (any) – The value to be stored in the node.

  • 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[, children, orig_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_descendants()

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.

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.

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