libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches

Defined in forest.hpp.

This class represents the collection of spanning trees of the strongly connected components of a word graph.

Public Types

using label_type = size_t
 Alias for the type of edge labels in a forest.
 
using node_type = size_t
 Alias for the type of nodes in a forest.
 

Public Member Functions

 Forest (Forest &&)=default
 Default move constructor.
 
 Forest (Forest const &)=default
 Default copy constructor.
 
 Forest (size_t n=0)
 Constructs a forest with n nodes.
 
Forestadd_nodes (size_t n)
 Add nodes to the Forest.
 
bool empty () const noexcept
 Check if there are any nodes in the forest.
 
Forestinit (size_t n=0)
 Reinitialize an existing Forest object.
 
label_type label (node_type i) const
 Returns the label of the edge from a node to its parent.
 
label_type label_no_checks (node_type i) const
 Returns the label of the edge from a node to its parent.
 
std::vector< label_type > const & labels () const noexcept
 Returns a const reference to the vector of edge labels.
 
size_t number_of_nodes () const noexcept
 Returns the number of nodes in the forest.
 
bool operator!= (Forest const &that) const
 Compare Forest objects for inequality.
 
Forestoperator= (Forest &&)=default
 Default move assignment constructor.
 
Forestoperator= (Forest const &)=default
 Default copy assignment constructor.
 
bool operator== (Forest const &that) const
 Compare Forest objects for equality.
 
node_type parent (node_type i) const
 Returns the parent of a node.
 
node_type parent_no_checks (node_type i) const
 Returns the parent of a node.
 
std::vector< node_type > const & parents () const noexcept
 Returns a const reference to the vector of parents.
 
template<typename Iterator>
Iterator path_to_root_no_checks (Iterator d_first, node_type i) const
 Store the labels of the edges on the path to a root node from i.
 
Forestset_parent_and_label (node_type node, node_type parent, label_type gen)
 Set the parent and edge label for a node.
 
Forestset_parent_and_label_no_checks (node_type node, node_type parent, label_type gen)
 Set the parent and edge label for a node.
 
void throw_if_node_out_of_bounds (node_type v) const
 Throw an exception if a node is out of bound.
 

Related Symbols

(Note that these are not member symbols.)

std::string to_human_readable_repr (Forest const &f)
 Return a human readable representation of a Forest object.
 

Constructor & Destructor Documentation

◆ Forest()

Forest ( size_t n = 0)
inlineexplicit

Constructs a forest with n nodes, that is initialised so that the parent() and label() of every node is UNDEFINED.

Parameters
nthe number of nodes, defaults to 0.

Member Function Documentation

◆ add_nodes()

Forest & add_nodes ( size_t n)

This function adds n nodes to the forest, but no edges.

Parameters
nthe number of nodes to add.
Exceptions
This function guarantees not to throw a LibsemigroupsException. If an exception is thrown, this is guaranteed not to be modified (strong exception guarantee).
Complexity
At most linear in number_of_nodes() + n.
Iterator validity
This function modifies the object defined by this, any iterators, pointers or references pointing into this may be invalidated by a call to this function.

◆ empty()

bool empty ( ) const
inlinenodiscardnoexcept

This function returns true if there are 0 nodes in the forest, and false otherwise.

Returns
A value of type bool.
Exceptions
This function is noexcept and is guaranteed never to throw.
Complexity
Constant

◆ init()

Forest & init ( size_t n = 0)

This function reinitializes an existing Forest object so that it is in the same state as if it had just be constructed as Forest(n).

Parameters
nthe number of nodes, defaults to 0.
Returns
A reference to this.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ label()

label_type label ( node_type i) const
inlinenodiscard

This function returns the label of the edge from the parent of i to the node i. The value UNDEFINED is returned if i has no parent, i.e. when i is a root node.

Parameters
ithe node whose label is sought.
Returns
A label_type.
Exceptions
LibsemigroupsExceptionif i exceeds number_of_nodes().
Complexity
Constant

◆ label_no_checks()

label_type label_no_checks ( node_type i) const
inlinenodiscard

This function returns the label of the edge from the parent of i to the node i. The value UNDEFINED is returned if i has no parent, i.e. when i is a root node.

Parameters
ithe node whose label is sought.
Returns
A label_type.
Complexity
Constant
Warning
No checks are performed on the arguments of this function.

◆ labels()

std::vector< label_type > const & labels ( ) const
inlinenodiscardnoexcept

Returns a const reference to the vector of edge labels in the Forest. The value in position i of this vector is the label of the edge from the parent of node i to i. If the parent equals UNDEFINED, then node i is a root node.

Returns
A std::vector<label_type>.
Exceptions
This function is noexcept and is guaranteed never to throw.
Complexity
Constant.

◆ number_of_nodes()

size_t number_of_nodes ( ) const
inlinenodiscardnoexcept

Returns the number of nodes in the forest.

Returns
A size_t.
Exceptions
This function is noexcept and is guaranteed never to throw.
Complexity
Constant

◆ operator!=()

bool operator!= ( Forest const & that) const
inlinenodiscard

This function returns the negation of operator==(that)

Parameters
thatthe Forest for comparison.
Returns
whether or not the Forest objects are not equal.

◆ operator==()

bool operator== ( Forest const & that) const
inlinenodiscard

This function returns true if and only if the parent and label of every node in this coincides with the parent and label in that.

Parameters
thatthe Forest for comparison.
Returns
whether or not the Forest objects are equal.

◆ parent()

node_type parent ( node_type i) const
inlinenodiscard

This function returns the parent of the node i in the forest. The value UNDEFINED is returned if i has no parent, i.e. when i is a root node.

Parameters
ithe node whose parent is sought.
Returns
A node_type.
Exceptions
LibsemigroupsExceptionif i exceeds number_of_nodes().
Complexity
Constant

◆ parent_no_checks()

node_type parent_no_checks ( node_type i) const
inlinenodiscard

This function returns the parent of the node i in the forest. The value UNDEFINED is returned if i has no parent, i.e. when i is a root node.

Parameters
ithe node whose parent is sought.
Returns
A node_type.
Complexity
Constant
Warning
No checks are performed on the arguments of this function.

◆ parents()

std::vector< node_type > const & parents ( ) const
inlinenodiscardnoexcept

Returns a const reference to the vector of parents in the Forest. The value in position i of this vector is the parent of node i. If the parent equals UNDEFINED, then node i is a root node.

Returns
A std::vector<node_type>.
Exceptions
This function is noexcept and is guaranteed never to throw.
Complexity
Constant.

◆ path_to_root_no_checks()

template<typename Iterator>
Iterator path_to_root_no_checks ( Iterator d_first,
node_type i ) const
inline

This function writes labels of the edges on the path to a root node from node i to the iterator d_first.

Template Parameters
IteratorThe type of the parameter, and the return type.
Parameters
d_firstthe output iterator.
ithe node.
Returns
An Iterator pointing one beyond the last letter inserted into d_first.
Warning
No checks are performed on the arguments of this function.

◆ set_parent_and_label()

Forest & set_parent_and_label ( node_type node,
node_type parent,
label_type gen )
inline

This function sets the parent of node to be parent, and the associated edge-label to be gen.

Parameters
nodethe node whose parent and label to set.
parentthe parent node.
genthe label of the edge from parent to node.
Returns
A reference to *this.
Exceptions
LibsemigroupsExceptionif node or parent exceeds number_of_nodes().
Complexity
Constant
Note
The value of gen can be arbitrary, and so this argument is never checked.

◆ set_parent_and_label_no_checks()

Forest & set_parent_and_label_no_checks ( node_type node,
node_type parent,
label_type gen )
inline

This function defines the parent and the label of the edge from that parent to the node node to be parent and gen respectively.

Parameters
nodethe node whose parent and label to set.
parentthe parent node.
genthe label of the edge from parent to node.
Exceptions
LibsemigroupsExceptionif node or parent exceeds number_of_nodes().
Complexity
Constant
Note
The value of gen can be arbitrary, and so this argument is never checked.
Warning
No checks are performed on the arguments of this function. In particular, if node or parent is greater than or equal to number_of_nodes, then bad things may happen.

◆ throw_if_node_out_of_bounds()

void throw_if_node_out_of_bounds ( node_type v) const

This function throws an exception if the node v is out of points.

Parameters
vthe node.

Friends And Related Symbol Documentation

◆ to_human_readable_repr()

std::string to_human_readable_repr ( Forest const & f)
related

Return a human readable representation of a Forest object.

Parameters
fthe Forest.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

The documentation for this class was generated from the following file: