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-helpers.hpp"
44#include "libsemigroups/word-graph.hpp"
46#include "felsch-graph.hpp"
47#include "node-manager.hpp"
50#include "word-graph-with-sources.hpp"
55 template <
typename Node>
56 class NodeManagedGraph :
public WordGraphWithSources<Node>,
57 public NodeManager<Node>,
64 using BaseGraph = WordGraphWithSources<Node>;
65 using node_type =
typename BaseGraph::node_type;
66 using label_type =
typename BaseGraph::label_type;
69 std::is_base_of<WordGraphWithSources<node_type>, BaseGraph>::value,
70 "the template parameter BaseGraph must be derived from "
71 "WordGraphWithSources<node_type>");
78 using Coincidence = std::pair<node_type, node_type>;
79 using Coincidences = std::stack<Coincidence>;
80 struct CollectCoincidences;
102 NodeManagedGraph& target_no_checks(node_type s,
104 node_type t)
noexcept {
105 _stats.num_edges_active += (t !=
UNDEFINED);
106 WordGraphWithSources<Node>::target_no_checks(s, a, t);
112 using BaseGraph::target_no_checks;
114 using NodeManager<node_type>::cursor;
115 using NodeManager<node_type>::lookahead_cursor;
122 NodeManagedGraph& init();
124 NodeManagedGraph(NodeManagedGraph
const&);
125 NodeManagedGraph(NodeManagedGraph&&);
126 NodeManagedGraph& operator=(NodeManagedGraph
const&);
127 NodeManagedGraph& operator=(NodeManagedGraph&&);
130 template <
typename OtherNode>
131 explicit NodeManagedGraph(WordGraph<OtherNode>
const& wg)
132 : BaseGraph(wg), NodeManager<node_type>() {
134 NodeManager<node_type>::add_active_nodes(
135 WordGraph<node_type>::number_of_nodes() - 1);
136 _stats.num_edges_active += wg.number_of_edges();
139 template <
typename OtherNode>
140 NodeManagedGraph& init(WordGraph<OtherNode>
const& wg) {
144 NodeManager<node_type>::add_active_nodes(
145 WordGraph<node_type>::number_of_nodes() - 1);
146 _stats.num_edges_active += wg.number_of_edges();
150 template <
typename OtherNode>
151 NodeManagedGraph& operator=(WordGraph<OtherNode>
const& wg);
153 NodeManagedGraph& reserve(
size_t n);
159 [[nodiscard]]
bool operator==(WordGraph<node_type>
const& that)
const {
160 return static_cast<WordGraph<node_type> const&
>(*this) == that;
167 NodeManagedGraph& large_collapse(
size_t val)
noexcept {
168 _settings.large_collapse = val;
172 [[nodiscard]]
size_t large_collapse() const noexcept {
173 return _settings.large_collapse;
180 [[nodiscard]] Stats& stats() noexcept {
184 [[nodiscard]] Stats& stats() const noexcept {
188 void stats_check_point()
const;
194 [[nodiscard]] uint64_t number_of_edges_active() const noexcept {
195 return _stats.num_edges_active;
199 [[nodiscard]] uint64_t count_number_of_edges_active() const noexcept;
205 node_type new_node();
207 template <
bool RegisterDefs = false>
208 [[nodiscard]] std::pair<
bool, node_type>
209 complete_path(node_type c,
211 word_type::const_iterator last) noexcept;
213 void merge_nodes_no_checks(node_type x, node_type y) {
214 _coinc.emplace(x, y);
217 template <
typename Functor = Noop>
218 void process_coincidences(Functor&& = Noop{});
220 void standardize(std::vector<node_type>
const& p,
221 std::vector<node_type>
const& q) {
222 BaseGraph::permute_nodes_no_checks(
223 p, q, NodeManager<node_type>::number_of_nodes_active());
224 NodeManager<node_type>::compact();
227 void permute_nodes_no_checks(std::vector<node_type>
const& p,
228 std::vector<node_type>
const& q) {
229 BaseGraph::permute_nodes_no_checks(
230 p, q, NodeManager<node_type>::number_of_nodes_active());
231 NodeManager<node_type>::apply_permutation(p);
236 void swap_nodes_no_checks(node_type c, node_type d);
239 namespace node_managed_graph {
240 template <
typename BaseGraph>
241 typename BaseGraph::node_type
242 random_active_node(NodeManagedGraph<BaseGraph>
const& nmg);
249#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