22#ifndef LIBSEMIGROUPS_WORD_GRAPH_VIEW_HPP_
23#define LIBSEMIGROUPS_WORD_GRAPH_VIEW_HPP_
30#include "word-graph.hpp"
32#include "detail/containers.hpp"
33#include "detail/int-range.hpp"
47 template <
typename Node>
51 "the template parameter Node must be an integral type!");
54 "the template parameter Node must be an unsigned integral type!");
68 typename detail::IntRange<Node>::const_iterator;
73 typename detail::IntRange<Node>::const_reverse_iterator;
77 typename detail::DynamicArray2<Node>::const_iterator;
89 to_view(rx::iterator_range<const_iterator_targets> it)
const {
91 | rx::transform([
this](
auto elem) {
return this->to_view(elem); });
97 in.second = to_view(in.second);
115 : _graph(&graph), _start(start), _end(end) {
116 LIBSEMIGROUPS_ASSERT(start <= end);
234 throw_if_graph_is_nullptr();
256 LIBSEMIGROUPS_ASSERT(start <= _end);
326 LIBSEMIGROUPS_ASSERT(_start <= _end);
327 return _end - _start;
417 return _graph->out_degree();
435 throw_if_graph_is_nullptr();
697 return to_view(_graph->targets_no_checks(translated));
733 return _graph->labels();
747 throw_if_graph_is_nullptr();
890 return to_view(_graph->target_no_checks(translated, a));
1013 template <
typename Iterator>
1054 template <
typename Iterator>
1074 this->throw_if_label_out_of_bounds(w);
1089 template <
typename Node2>
1106 template <
typename Iterator1,
typename Iterator2>
1108 for (
auto it = first; it != last; ++it) {
1137 throw_if_graph_is_nullptr();
1142 void throw_if_graph_is_nullptr()
const {
1143 if (_graph ==
nullptr) {
1148 void throw_if_endpoint_out_of_bounds(
node_type endpoint,
1149 std::string_view node_name)
const;
1154 throw_if_endpoint_out_of_bounds(start,
"start");
1155 throw_if_endpoint_out_of_bounds(end,
"end");
1156 throw_if_endpoints_wrong_order(start, end);
1160#include "word-graph-view.tpp"
Class for representing word graphs.
Definition word-graph.hpp:83
Node label_type
The type of edge labels in a word graph.
Definition word-graph.hpp:102
size_type number_of_nodes() const noexcept
Returns the number of nodes.
Definition word-graph.hpp:766
size_type number_of_nodes() const
The number of nodes that this view ranges over.
Definition word-graph-view.hpp:342
Node node_type
The type of nodes in a word graph.
Definition word-graph-view.hpp:57
auto labels_and_targets(node_type source) const
Returns a range object containing pairs consisting of edge labels and target nodes.
Definition word-graph-view.hpp:863
size_type out_degree_no_checks() const noexcept
Returns the out degree.
Definition word-graph-view.hpp:416
std::pair< label_type, node_type > next_label_and_target_no_checks(node_type s, label_type a) const
Get the next target of an edge incident to a given node that doesn't equal UNDEFINED.
WordGraphView & start_node(node_type start)
Set the index in the underlying graph of the first node in the view.
WordGraph< Node > const * word_graph() const noexcept
Returns a const pointer to the underlying WordGraph.
Definition word-graph-view.hpp:451
void throw_if_any_target_out_of_bounds() const
Throws if the target of any edge is out of bounds.
Definition word-graph-view.hpp:989
bool not_equal_to_no_checks(WordGraphView const &that) const
Compares two word graph views to see if they are not equal.
Definition word-graph-view.hpp:955
size_type number_of_edges() const
The number of edges in the underlying graph.
Definition word-graph-view.hpp:371
WordGraphView & init(WordGraph< Node > const &graph, size_type start, size_type end)
Re-initialize the view to be a view over graph over the range start to end.
bool operator!=(WordGraphView const &that) const
Compares two word graph views to see if they are not equal.
Definition word-graph-view.hpp:973
auto labels_no_checks() const noexcept
Returns a range object containing all labels of edges in a word graph.
Definition word-graph-view.hpp:732
const_iterator_nodes cbegin_nodes_no_checks() const noexcept
Returns a random access iterator pointing at the first node of the word graph.
Definition word-graph-view.hpp:473
auto labels() const
Returns a range object containing all labels of edges in a word graph.
Definition word-graph-view.hpp:746
size_type number_of_nodes_no_checks() const noexcept
The number of nodes that this view ranges over.
Definition word-graph-view.hpp:325
Node label_type
The type of edge labels in a word graph.
Definition word-graph-view.hpp:60
auto cbegin_targets_no_checks(node_type source) const noexcept
Returns a random access iterator pointing at the target of the edge with label 0 incident to a given ...
Definition word-graph-view.hpp:592
auto labels_and_targets_no_checks(node_type source) const noexcept
Returns a range object containing pairs consisting of edge labels and target nodes.
Definition word-graph-view.hpp:844
auto targets(node_type source) const
Returns a range object containing all the targets of edges with a given source.
Definition word-graph-view.hpp:716
WordGraphView(WordGraph< Node > const &graph, size_type start, size_type end)
Construct from a WordGraph and range of nodes.
Definition word-graph-view.hpp:114
void throw_if_invalid_view() const
Throws if the this is in an invalid state.
Definition word-graph-view.hpp:1136
WordGraphView(WordGraphView< Node > &&)=default
Default move constructor.
WordGraphView & operator=(WordGraphView< Node > &&)=default
Default move assignment.
WordGraphView & operator=(WordGraphView< Node > const &)=default
Default copy assignment.
void throw_if_node_out_of_bounds(Iterator1 first, Iterator2 last) const
Throws if any node in a range is out of bounds.
Definition word-graph-view.hpp:1107
node_type end_node() const noexcept
The index in the underlying graph of one beyond the final node in the view.
Definition word-graph-view.hpp:401
WordGraphView & reshape(node_type start, node_type end)
Reshape this view over the same graph.
Definition word-graph-view.hpp:233
WordGraphView & end_node(node_type end)
Set the index in the underlying graph of one beyond the last node in the view.
node_type target(node_type source, label_type a) const
Get the target of the edge with given source node and label.
WordGraphView & init(WordGraph< Node > const &graph)
Re-initialize the view to be a view over graph.
Definition word-graph-view.hpp:158
WordGraphView()
Default constructor.
Definition word-graph-view.hpp:165
WordGraphView & end_node_no_checks(node_type end) noexcept
Set the index in the underlying graph of one beyond the last node in the view.
void throw_if_node_out_of_bounds(Node2 n) const
Throws if a node is out of bounds.
WordGraphView & start_node_no_checks(node_type start) noexcept
Set the index in the underlying graph of the first node in the view.
Definition word-graph-view.hpp:255
WordGraphView & reshape_no_checks(node_type start, node_type end)
Reshape this view over the same graph.
auto cbegin_targets(node_type source) const
Returns a random access iterator pointing at the target of the edge with label 0 incident to a given ...
Definition word-graph-view.hpp:618
void throw_if_label_out_of_bounds(word_type const &word) const
Throws if word contains labels that are out of bounds.
Definition word-graph-view.hpp:1037
void throw_if_label_out_of_bounds(std::vector< word_type > const &rules) const
Throws if any of the labels in vector of words is out of bounds.
Definition word-graph-view.hpp:1072
typename detail::DynamicArray2< Node >::const_iterator const_iterator_targets
The type of an iterator pointing to the targets of a node.
Definition word-graph-view.hpp:76
const_iterator_nodes cbegin_nodes() const
Returns a random access iterator pointing at the first node of the word graph.
Definition word-graph-view.hpp:494
void throw_if_invalid_range() const
Throws if the range specified by [start_node(), end_node()] is invalid.
Definition word-graph-view.hpp:1122
node_type start_node() const noexcept
The index in the underlying graph of the first node in the view.
Definition word-graph-view.hpp:386
void throw_if_label_out_of_bounds(typename WordGraph< Node >::label_type a) const
Throws if a label is out of bounds.
void throw_if_any_target_out_of_bounds(Iterator first, Iterator last) const
Throws if the target of any edge with source in a given range is out of bounds.
const_iterator_nodes cend_nodes() const
Returns a random access iterator pointing one past the last node of the range of this word graph view...
Definition word-graph-view.hpp:533
size_type number_of_edges_no_checks() const noexcept
The number of edges in the underlying graph.
WordGraphView & init()
Re-initialize the view as if it had been default constructed.
Definition word-graph-view.hpp:174
size_type out_degree() const
Returns the out degree.
Definition word-graph-view.hpp:434
auto nodes_no_checks() const noexcept
Returns a range object containing all nodes in a word graph.
Definition word-graph-view.hpp:547
std::pair< label_type, node_type > next_label_and_target(node_type s, label_type a) const
Get the next target of an edge incident to a given node that doesn't equal UNDEFINED.
typename detail::IntRange< Node >::const_reverse_iterator const_reverse_iterator_nodes
The type of a reverse iterator pointing to the nodes of a word graph view.
Definition word-graph-view.hpp:72
void throw_if_label_out_of_bounds(Iterator first, Iterator last) const
Throws if range contains labels that are out of bounds.
Definition word-graph-view.hpp:1055
bool equal_to_no_checks(WordGraphView const &that) const
Compares two word graph views to see if they are equal.
node_type target_no_checks(node_type source, label_type a) const
Get the target of the edge with given source node and label.
Definition word-graph-view.hpp:887
auto cend_targets_no_checks(node_type source) const noexcept
Returns a random access iterator pointing one beyond the target of the edge with label out_degree() -...
Definition word-graph-view.hpp:646
auto targets_no_checks(node_type source) const noexcept
Returns a range object containing all the targets of edges with a given source.
Definition word-graph-view.hpp:695
const_iterator_nodes cend_nodes_no_checks() const noexcept
Returns a random access iterator pointing one past the last node of the range of this word graph view...
Definition word-graph-view.hpp:513
typename detail::IntRange< Node >::const_iterator const_iterator_nodes
The type of an iterator pointing to the nodes of the word graph view.
Definition word-graph-view.hpp:67
WordGraphView(WordGraphView< Node > const &)=default
Default copy constructor.
WordGraphView(WordGraph< Node > const &graph)
Construct from a WordGraph.
Definition word-graph-view.hpp:145
auto nodes() const
Returns a range object containing all nodes in a word graph.
Definition word-graph-view.hpp:563
std::size_t size_type
Unsigned integer type.
Definition word-graph-view.hpp:63
bool operator==(WordGraphView const &that) const
Compares two word graph views to see if they are equal.
auto cend_targets(node_type source) const
Returns a random access iterator pointing one beyond the target of the edge with label out_degree() -...
Definition word-graph-view.hpp:672
#define LIBSEMIGROUPS_EXCEPTION(...)
Throw a LibsemigroupsException.
Definition exception.hpp:99
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:99
size_t letter_type
Type for the index of a generator of a semigroup.
Definition types.hpp:96
Namespace for everything in the libsemigroups library.
Definition action.hpp:44