The Forest class
This class represents the collection of spanning trees of the strongly connected components of a word graph.
Contents
This class represents the collection of spanning trees of the strongly connected components of a word graph. |
|
Add nodes to the |
|
|
Copy a |
|
Check if there are any nodes in the forest. |
|
Reinitialize an existing |
|
Returns the label of the edge from a node to its parent. |
Returns a copy of the list of edge labels in the |
|
Returns the number of nodes in the forest. |
|
Returns the parent of a node. |
|
Returns a list of parents in the |
|
Returns a list containing the labels of the edges on the path from a root node to i. |
|
Set the parent and edge label for a node. |
Full API
- class Forest
- __init__(*args, **kwargs)
Overloaded function.
- __init__(self: Forest, n: int = 0) None
Constructs a forest with n nodes.
Constructs a forest with n nodes, that is initialised so that the
Forest.parentandForest.labelof every node isUNDEFINED.- Parameters:
n (int) – the number of nodes, defaults to
0.
- __init__(self: Forest, parents: list[int | Undefined], labels: list[int | Undefined]) None
Construct a
Forestfrom list of parents and labels.- Parameters:
- Raises:
LibsemigroupsError – if parent and labels have different sizes;
LibsemigroupsError – parent and labels do not have the value
UNDEFINEDin the same positions (these values indicate where the roots of the trees in the forest are located and so must coincide).LibsemigroupsError –
set_parent_and_labelthrows forparent[i]andedge_labels[i]for any value ofi.
- add_nodes(self: Forest, n: int) None
Add nodes to the
Forest.This function adds n nodes to the forest, but no edges.
- Parameters:
n (int) – the number of nodes to add.
- Complexity:
At most linear in
number_of_nodes() + n.
- empty(self: Forest) bool
Check if there are any nodes in the forest. This function returns
Trueif there are0nodes in the forest, andFalseotherwise.- Returns:
Whether or not the forest is empty.
- Return type:
- Complexity:
Constant.
- init(self: Forest, n: int) Forest
Reinitialize an existing
Forestobject.This function reinitializes an existing
Forestobject so that it is in the same state as if it had just be constructed asForest(n).
- label(self: Forest, i: int) int | Undefined
Returns the label of the edge from a node to its parent.
- Parameters:
i (int) – the node whose label is sought.
- Returns:
The label of the edge from the parent of i to i.
- Return type:
- Raises:
LibsemigroupsError – if i exceeds
number_of_nodes().- Complexity:
Constant.
- labels(self: Forest) list[int | Undefined]
Returns a copy of the list of edge labels in the
Forest. The value in position i of this list is the label of the edge from the parent of node i to i. If the parent equalsUNDEFINED, then node i is a root node.
- number_of_nodes(self: Forest) int
Returns the number of nodes in the forest. Returns the number of nodes in the forest.
- Returns:
The number of nodes in the forest.
- Return type:
- Complexity:
Constant.
- parent(self: Forest, i: int) int | Undefined
Returns the parent of a node.
- Parameters:
i (int) – the node whose parent is sought.
- Returns:
The parent of i.
- Return type:
- Raises:
LibsemigroupsError – if i exceeds
number_of_nodes().- Complexity:
Constant
- parents(self: Forest) list[int | Undefined]
Returns a list of parents in the
Forest. The value in positioniof this list is the parent of nodei. If the parent equalsUNDEFINED, then nodeiis a root node.
- path_to_root(self: Forest, i: int) list[int]
Returns a list containing the labels of the edges on the path from a root node to i.
- Parameters:
i (int) – the node.
- Returns:
The word labelling the path from the root to i.
- Return type:
- Raises:
LibsemigroupsError – if i is greater than or equal to
number_of_nodes.
- set_parent_and_label(self: Forest, node: int, parent: int, gen: int) Forest
Set the parent and edge label for a node. This function sets the parent of node to be parent, and the associated edge-label to be gen.
- Parameters:
- Returns:
self
- Return type:
- Raises:
LibsemigroupsError – if node or parent exceeds
number_of_nodes().- Complexity:
Constant.