31#ifndef LIBSEMIGROUPS_DETAIL_WORD_GRAPH_WITH_SOURCES_HPP_
32#define LIBSEMIGROUPS_DETAIL_WORD_GRAPH_WITH_SOURCES_HPP_
44#include "libsemigroups/config.hpp"
45#include "libsemigroups/constants.hpp"
46#include "libsemigroups/types.hpp"
47#include "libsemigroups/word-graph.hpp"
49#include "containers.hpp"
54 template <
typename Node>
55 class WordGraphWithSources :
public WordGraph<Node> {
57 using node_type = Node;
58 using label_type =
typename WordGraph<Node>::label_type;
59 using size_type =
typename WordGraph<Node>::size_type;
62 detail::DynamicArray2<node_type> _preim_init;
63 detail::DynamicArray2<node_type> _preim_next;
70 explicit WordGraphWithSources(size_type m = 0, size_type n = 0)
71 : WordGraph<node_type>(m, n),
75 void init(size_type m = 0, size_type n = 0);
77 template <
typename ThatNode>
78 explicit WordGraphWithSources(WordGraph<ThatNode>
const& that);
80 template <
typename ThatNode>
81 void init(WordGraph<ThatNode>
const& that);
83 template <
typename ThatNode>
84 explicit WordGraphWithSources(WordGraph<ThatNode>&& that);
86 template <
typename ThatNode>
87 void init(WordGraph<ThatNode>&& that);
89 WordGraphWithSources(WordGraphWithSources&&) =
default;
90 WordGraphWithSources(WordGraphWithSources
const&) =
default;
91 WordGraphWithSources& operator=(WordGraphWithSources
const&) =
default;
92 WordGraphWithSources& operator=(WordGraphWithSources&&) =
default;
94 ~WordGraphWithSources();
97 template <
bool = true>
98 void target_no_checks(node_type c, label_type x, node_type d)
noexcept {
103 add_source_no_checks(d, x, c);
109 [[nodiscard]] node_type target(node_type v, label_type lbl)
const {
113 [[nodiscard]] node_type target_no_checks(node_type v,
114 label_type lbl)
const {
118 void remove_target_no_checks(node_type c, label_type x)
noexcept {
121 remove_source_no_checks(WordGraph<Node>::target_no_checks(c, x), x, c);
125 void add_nodes(size_type m) {
127 _preim_init.add_rows(m);
128 _preim_next.add_rows(m);
131 void add_to_out_degree(size_type m) {
132 _preim_init.add_cols(m);
133 _preim_next.add_cols(m);
137 inline node_type first_source_no_checks(node_type c,
141 LIBSEMIGROUPS_ASSERT(c < _preim_init.number_of_rows());
142 LIBSEMIGROUPS_ASSERT(x < _preim_init.number_of_cols());
143 return _preim_init.get(c, x);
146 inline node_type next_source_no_checks(node_type c,
150 LIBSEMIGROUPS_ASSERT(c < _preim_next.number_of_rows());
151 LIBSEMIGROUPS_ASSERT(x < _preim_next.number_of_cols());
152 return _preim_next.get(c, x);
155 void induced_subgraph_no_checks(node_type first, node_type last);
159 void permute_nodes_no_checks(std::vector<node_type>
const& p,
160 std::vector<node_type>
const& q,
165 void swap_nodes_no_checks(node_type c, node_type d);
171 void rename_node_no_checks(node_type c, node_type d);
173 template <
typename NewEdgeFunc,
typename IncompatibleFunc>
174 void merge_nodes_no_checks(node_type min,
176 NewEdgeFunc&& new_edge,
177 IncompatibleFunc&& incompat);
180 bool is_source_no_checks(node_type c, label_type x, node_type d)
const;
182 void remove_all_sources_and_targets_no_checks(node_type c);
183 void remove_all_sources_no_checks(node_type c);
185 void add_source_no_checks(node_type c,
187 node_type d)
noexcept;
189 template <
typename It>
190 void rebuild_sources_no_checks(It first, It last);
193 void disjoint_union_inplace_no_checks(WordGraph<Node>
const& that) {
195 add_nodes(that.number_of_nodes());
196 for (
auto s : that.nodes()) {
197 for (
auto [a, t] : that.labels_and_targets_no_checks(s)) {
199 target_no_checks(s + N, a, t + N);
206 void remove_source_no_checks(node_type cx, label_type x, node_type d);
207 void replace_target_no_checks(node_type c, label_type x, node_type d);
208 void replace_source_no_checks(node_type c,
216#include "word-graph-with-sources.tpp"
size_type out_degree() const noexcept
Returns the out-degree.
Definition word-graph.hpp:823
WordGraph & target(node_type s, label_type a, node_type t)
Add an edge from one node to another with a given label.
WordGraph & add_nodes(size_type nr)
Add a number of new nodes.
WordGraph & target_no_checks(node_type s, label_type a, node_type t)
Add an edge from one node to another with a given label.
Definition word-graph.hpp:355
WordGraph & remove_target_no_checks(node_type s, label_type a)
Remove an edge from a node with a given label.
Definition word-graph.hpp:377
WordGraph & add_to_out_degree(size_type nr)
Add to the out-degree of every node.
size_type number_of_nodes() const noexcept
Returns the number of nodes.
Definition word-graph.hpp:747
Undefined const UNDEFINED
Value for something undefined.
size_t letter_type
Type for the index of a generator of a semigroup.
Definition types.hpp:98
Namespace for everything in the libsemigroups library.
Definition action.hpp:44