43# ifndef GRAPH_TRAVERSE_H
44# define GRAPH_TRAVERSE_H
72template <
class GT,
class Itor,
91 template <
class Node_Op>
104 for (Itor it(start,
sa); it.has_curr(); it.next_ne())
106 typename GT::Arc *a = it.get_curr();
113 const size_t n =
g.
vsize();
116 typename GT::Arc *arc = q.get();
132 for (Itor it(curr,
sa); it.has_curr(); it.next_ne())
134 typename GT::Arc *a = it.get_curr();
154 template <
class Node_Op>
157 return (*
this)(start, op);
178 if (
not op(start,
nullptr))
181 using Pair = std::tuple<typename GT::Node *, typename GT::Arc *>;
183 for (Itor it(start,
sa); it.has_curr(); it.next_ne())
185 typename GT::Arc *a = it.get_curr();
189 q.put(std::make_tuple(start, a));
192 const size_t n =
g.
vsize();
195 const Pair p = q.get();
205 if (
not op(curr, arc))
208 for (Itor it(curr,
sa); it.has_curr(); it.next_ne())
210 typename GT::Arc *a = it.get_curr();
218 q.put(std::make_tuple(curr, a));
229 template <
class Operation>
232 return exec(start, op);
242 template <
class Node_Op,
class Arc_Op>
251 size_t node_count = 1;
256 return std::make_tuple(1, 0);
258 for (Itor it(start,
sa); it.has_curr(); it.next_ne())
260 typename GT::Arc *a = it.get_curr();
267 return std::make_tuple(node_count,
arc_count);
272 typename GT::Arc *arc = q.get();
286 return std::make_tuple(node_count,
arc_count);
288 for (Itor it(curr,
sa); it.has_curr(); it.next_ne())
290 typename GT::Arc *a = it.get_curr();
301 return std::make_tuple(node_count,
arc_count);
308 return std::make_tuple(node_count,
arc_count);
312 template <
class Node_Op,
class Arc_Op>
314 Node_Op &&
node_op = Node_Op(),
322template <
class GT,
class Itor,
326template <
class GT,
class Itor,
Dynamic stack of elements of generic type T based on a singly linked list.
constexpr bool is_empty() const noexcept
Return true if list is empty.
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
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)
Traverse a graph depth-first or breadth-first and execute a visit function.
size_t operator()(typename GT::Node *start, Node_Op &op)
Traverse the graph starting from start and execute op on each node.
Graph_Traverse(GT &__g, Show_Arc __sa=Show_Arc())
Construct a traverser with a graph and arc filter.
size_t exec(typename GT::Node *start, Operation &&op=Operation())
This is an overloaded member function, provided for convenience. It differs from the above function o...
size_t exec(typename GT::Node *start, Op &op)
Execute operation op(curr, arc) where curr is the visited node and arc is the incoming arc.
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
DynList< T > maps(const C &c, Op op)
Classic map operation.
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.
Arc of graph implemented with double-linked adjacency lists.
Array-based graph implementation.
Dynamic queue implementation based on linked lists.
Dynamic stack implementation based on linked lists.