26#ifndef LIBSEMIGROUPS_DETAIL_NODE_MANAGED_GRAPH_HPP_
27#define LIBSEMIGROUPS_DETAIL_NODE_MANAGED_GRAPH_HPP_
40#include "libsemigroups/presentation.hpp"
41#include "libsemigroups/runner.hpp"
42#include "libsemigroups/types.hpp"
43#include "libsemigroups/word-graph.hpp"
45#include "felsch-graph.hpp"
46#include "node-manager.hpp"
49#include "word-graph-with-sources.hpp"
54 template <
typename Node>
55 class NodeManagedGraph :
public WordGraphWithSources<Node>,
56 public NodeManager<Node>,
63 using BaseGraph = WordGraphWithSources<Node>;
64 using node_type =
typename BaseGraph::node_type;
65 using label_type =
typename BaseGraph::label_type;
68 std::is_base_of<WordGraphWithSources<node_type>, BaseGraph>::value,
69 "the template parameter BaseGraph must be derived from "
70 "WordGraphWithSources<node_type>");
77 using Coincidence = std::pair<node_type, node_type>;
78 using Coincidences = std::stack<Coincidence>;
79 struct CollectCoincidences;
101 NodeManagedGraph& target_no_checks(node_type s,
103 node_type t)
noexcept {
104 _stats.num_edges_active += (t !=
UNDEFINED);
105 WordGraphWithSources<Node>::target_no_checks(s, a, t);
111 using BaseGraph::target_no_checks;
113 using NodeManager<node_type>::cursor;
114 using NodeManager<node_type>::lookahead_cursor;
121 NodeManagedGraph& init();
123 NodeManagedGraph(NodeManagedGraph
const&);
124 NodeManagedGraph(NodeManagedGraph&&);
125 NodeManagedGraph& operator=(NodeManagedGraph
const&);
126 NodeManagedGraph& operator=(NodeManagedGraph&&);
129 template <
typename OtherNode>
130 explicit NodeManagedGraph(WordGraph<OtherNode>
const& wg)
131 : BaseGraph(wg), NodeManager<node_type>() {
133 NodeManager<node_type>::add_active_nodes(
134 WordGraph<node_type>::number_of_nodes() - 1);
135 _stats.num_edges_active += wg.number_of_edges();
138 template <
typename OtherNode>
139 NodeManagedGraph& init(WordGraph<OtherNode>
const& wg) {
143 NodeManager<node_type>::add_active_nodes(
144 WordGraph<node_type>::number_of_nodes() - 1);
145 _stats.num_edges_active += wg.number_of_edges();
149 template <
typename OtherNode>
150 NodeManagedGraph& operator=(WordGraph<OtherNode>
const& wg);
152 NodeManagedGraph& reserve(
size_t n);
158 [[nodiscard]]
bool operator==(WordGraph<node_type>
const& that)
const {
159 return static_cast<WordGraph<node_type> const&
>(*this) == that;
166 NodeManagedGraph& large_collapse(
size_t val)
noexcept {
167 _settings.large_collapse = val;
171 [[nodiscard]]
size_t large_collapse() const noexcept {
172 return _settings.large_collapse;
179 [[nodiscard]] Stats& stats() noexcept {
183 [[nodiscard]] Stats& stats() const noexcept {
187 void stats_check_point()
const;
193 [[nodiscard]] uint64_t number_of_edges_active() const noexcept {
194 return _stats.num_edges_active;
198 [[nodiscard]] uint64_t count_number_of_edges_active() const noexcept;
204 node_type new_node();
206 template <
bool RegisterDefs = false>
207 [[nodiscard]] std::pair<
bool, node_type>
208 complete_path(node_type c,
210 word_type::const_iterator last) noexcept;
212 void merge_nodes_no_checks(node_type x, node_type y) {
213 _coinc.emplace(x, y);
216 template <
typename Functor = Noop>
217 void process_coincidences(Functor&& = Noop{});
219 void standardize(std::vector<node_type>
const& p,
220 std::vector<node_type>
const& q) {
221 BaseGraph::permute_nodes_no_checks(
222 p, q, NodeManager<node_type>::number_of_nodes_active());
223 NodeManager<node_type>::compact();
226 void permute_nodes_no_checks(std::vector<node_type>
const& p,
227 std::vector<node_type>
const& q) {
228 BaseGraph::permute_nodes_no_checks(
229 p, q, NodeManager<node_type>::number_of_nodes_active());
230 NodeManager<node_type>::apply_permutation(p);
235 void swap_nodes_no_checks(node_type c, node_type d);
238 namespace node_managed_graph {
239 template <
typename BaseGraph>
240 typename BaseGraph::node_type
241 random_active_node(NodeManagedGraph<BaseGraph>
const& nmg);
248#include "node-managed-graph.tpp"
size_type out_degree() const noexcept
Returns the out-degree.
Definition word-graph.hpp:842
Undefined const UNDEFINED
Value for something undefined.
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:99
Namespace for everything in the libsemigroups library.
Definition action.hpp:44