70#ifndef GRAPH_TRAVERSE_GENERATORS_H
71#define GRAPH_TRAVERSE_GENERATORS_H
85namespace graph_traverse_generator_detail
92enum class Traverse_State :
unsigned char
130template <AlephGraph
GT,
class Itor,
135 using State = graph_traverse_generator_detail::Traverse_State;
140 static unsigned char raw(
State s)
noexcept {
return static_cast<unsigned char>(s); }
151 if (tgt->state() !=
raw(State::Unprocessed))
153 a->set_state(
raw(State::Processed));
156 a->set_state(
raw(State::Processing));
157 tgt->set_state(
raw(State::Processing));
195 <<
"Graph_Traverse_Generator::traverse(): null start node";
200 start->set_state(
raw(State::Processed));
203 Q<typename GT::Arc *> q;
204 for (Itor it(start,
sa_); it.has_curr(); it.next_ne())
206 typename GT::Arc *a = it.get_curr();
213 while (not q.is_empty()
and count < n)
215 typename GT::Arc *arc = q.get();
216 assert(arc->
state() ==
raw(State::Processing));
225 assert(curr->
state() ==
raw(State::Processing));
230 for (Itor it(curr,
sa_); it.has_curr(); it.next_ne())
232 typename GT::Arc *a = it.get_curr();
233 if (a->
state() !=
raw(State::Unprocessed))
245template <
class GT,
class Itor,
class Show_Arc = Dft_Show_Arc<GT>>
251template <
class GT,
class Itor,
class Show_Arc = Dft_Show_Arc<GT>>
Exception handling system with formatted messages for Aleph-w.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Lazy sequence type (Aleph::Generator<T>) built on C++20 coroutines.
C++20 concepts for the protocol shared by graph algorithms.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Dynamic stack of elements of generic type T based on a singly linked list.
Lazy, single-pass sequence of T values produced by a coroutine.
Lazily traverse a graph depth-first or breadth-first.
Graph_Traverse_Generator(GT &__g, Show_Arc __sa=Show_Arc())
Construct a lazy traverser bound to graph __g with arc filter __sa.
static bool seed_arc(typename GT::Arc *a, typename GT::Node *tgt) noexcept
Prepare arc a (leading to tgt) for frontier expansion, and report whether the caller should enqueue i...
graph_traverse_generator_detail::Traverse_State State
Aleph::Generator< typename GT::Node * > traverse(typename GT::Node *start) &
Lazily traverse the graph from start.
static unsigned char raw(State s) noexcept
void set_state(unsigned int s) noexcept
Set the state of arc to value s
unsigned int state() const noexcept
Return the state of arc.
unsigned int state() const noexcept
Return the state's value.
void set_state(unsigned int s) noexcept
Set the state to value s
void reset_arcs() const
Reset all the arcs of graph (the control bits, the state, the counter and the cookie)
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
constexpr size_t vsize() const noexcept
See get_num_nodes().
void reset_nodes() const
Reset all the nodes of graph (the control bits, the state, the counter and the cookie)
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Graph traversal algorithms (DFS, BFS).
const unsigned char Processed
The node or arc has already been processed.
const unsigned char Processing
The node are being processed; probably it is inside a queue, stack or heap.
const unsigned char Unprocessed
The node have not bees processed.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Default filter for filtered iterators on arcs.