19#ifndef LIBSEMIGROUPS_FOREST_HPP_
20#define LIBSEMIGROUPS_FOREST_HPP_
24#include <initializer_list>
28#include "constants.hpp"
30#include "exception.hpp"
60 : _edge_label(n, static_cast<size_t>(
UNDEFINED)),
61 _parent(n, static_cast<size_t>(
UNDEFINED)) {}
99 return _parent == that._parent && _edge_label == that._edge_label;
110 return !(*
this == that);
143 [[nodiscard]]
bool empty() const noexcept {
144 return _parent.empty();
172 _edge_label[node] = gen;
217 return _parent.size();
278 return _edge_label[i];
297 return _edge_label[i];
352 template <
typename Iterator>
354 LIBSEMIGROUPS_ASSERT(i < _parent.size());
355 LIBSEMIGROUPS_ASSERT(i < _edge_label.size());
406 template <
typename Return>
409 if (parent.
size() != edge_labels.
size()) {
411 "expected the 1st and 2nd arguments (parents and edge labels) to "
412 "have equal size equal, found {} != {}",
416 size_t const num_nodes = parent.
size();
418 for (
size_t i = 0; i < num_nodes; ++i) {
419 auto p = *(parent.
begin() + i);
420 auto l = *(edge_labels.
begin() + i);
425 "roots not at the same indices in the 1st and 2nd arguments "
426 "(parents and edge labels), expected UNDEFINED at index {} found "
459 template <
typename Return>
548 struct formatter<
libsemigroups::Forest> : formatter<std::string> {
569 template <
typename FormatContext>
571 return formatter<string_view>::format(
Class representing a collection of spanning trees of a word graph.
Definition forest.hpp:42
size_t number_of_nodes() const noexcept
Returns the number of nodes in the forest.
Definition forest.hpp:216
Forest & init(size_t n=0)
Reinitialize an existing Forest object.
bool empty() const noexcept
Check if there are any nodes in the forest.
Definition forest.hpp:143
node_type parent_no_checks(node_type i) const
Returns the parent of a node.
Definition forest.hpp:256
Forest(Forest const &)=default
Default copy constructor.
Forest & operator=(Forest const &)=default
Default copy assignment constructor.
bool operator==(Forest const &that) const
Compare Forest objects for equality.
Definition forest.hpp:98
std::vector< node_type > const & parents() const noexcept
Returns a const reference to the vector of parents.
Definition forest.hpp:314
Forest & operator=(Forest &&)=default
Default move assignment constructor.
node_type parent(node_type i) const
Returns the parent of a node.
Definition forest.hpp:236
std::string to_human_readable_repr(Forest const &f)
Return a human readable representation of a Forest object.
Forest(size_t n=0)
Constructs a forest with n nodes.
Definition forest.hpp:59
Forest & add_nodes(size_t n)
Add nodes to the Forest.
bool operator!=(Forest const &that) const
Compare Forest objects for inequality.
Definition forest.hpp:109
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.
Definition forest.hpp:353
label_type label(node_type i) const
Returns the label of the edge from a node to its parent.
Definition forest.hpp:276
Forest & set_parent_and_label_no_checks(node_type node, node_type parent, label_type gen)
Set the parent and edge label for a node.
Definition forest.hpp:168
size_t label_type
Alias for the type of edge labels in a forest.
Definition forest.hpp:51
size_t node_type
Alias for the type of nodes in a forest.
Definition forest.hpp:48
label_type label_no_checks(node_type i) const
Returns the label of the edge from a node to its parent.
Definition forest.hpp:296
std::vector< label_type > const & labels() const noexcept
Returns a const reference to the vector of edge labels.
Definition forest.hpp:333
void throw_if_node_out_of_bounds(node_type v) const
Throw an exception if a node is out of bound.
Forest & set_parent_and_label(node_type node, node_type parent, label_type gen)
Set the parent and edge label for a node.
Definition forest.hpp:196
Forest(Forest &&)=default
Default move constructor.
Undefined const UNDEFINED
Value for something undefined.
#define LIBSEMIGROUPS_EXCEPTION(...)
Throw a LibsemigroupsException.
Definition exception.hpp:95
enable_if_is_same< Return, Blocks > make(Container const &cont)
Check the arguments, construct a Blocks object, and check it.
Definition bipart.hpp:798
std::enable_if_t< std::is_same_v< Given, Expected >, Expected > enable_if_is_same
Alias equal to the second template parameter if both template parameters are equal.
Definition types.hpp:50
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:101
auto format(libsemigroups::Forest const &f, FormatContext &ctx) const
Custom formatter for Forest objects.
Definition forest.hpp:570
Helper functions for the Forest class.
Definition forest.hpp:483
void path_to_root(Forest const &f, word_type &w, Forest::node_type i)
Modifies w to contain the labels of the edges on the path to a root node from i.
void path_to_root_no_checks(Forest const &f, word_type &w, Forest::node_type i)
Modifies w to contain the labels of the edges on the path to a root node from i.
Namespace for everything in the libsemigroups library.
Definition action.hpp:44