96# ifndef GRAPH_TO_TREE_H
97# define GRAPH_TO_TREE_H
112 namespace graph_to_tree_detail
117 template <
class GT,
typename Key,
class SA>
124 template <
class... Args>
140 if (
it.get_current_arc_ne() !=
from)
141 return it.get_tgt_node_ne();
153 template <
class GT,
typename Key,
class SA,
class Convert,
class... Args>
155 typename GT::Node * groot, Args &&... args)
160 auto child_of = [&convert](
Frame & f,
typename GT::Node * gtgt)
165 convert(gtgt, ttgt.get());
168 return ttgt.release();
176 std::optional<Frame> here(std::in_place, troot,
nullptr, groot, args...);
179 if (
auto gtgt = here->next_target())
181 auto child = child_of(*here, gtgt);
182 auto arc = here->it.get_current_arc_ne();
183 frames.
push(std::move(*here));
184 here.emplace(child, arc, gtgt, args...);
197 here.emplace(child_of(f, gtgt), f.
it.get_current_arc_ne(),
207 template <AlephGraph GT,
typename Key,
typename Convert, ArcFilter<GT> SA>
static inline
258 template <AlephGraph
GT,
typename Key,
265 <<
"Graph is not a tree (not acyclique)";
270 Convert () (groot, troot);
272 __graph_to_tree_node <GT, Key, Convert, SA> (g, groot, troot, sa);
317 template <AlephGraph
GT,
typename Key,
328 graph_to_tree_detail::build<GT, Key, SA>(troot, *
convert, groot,
sa);
337 <<
"Graph is not a tree (not acyclique)";
344 (*convert) (groot, troot);
391 template <AlephGraph GT,
typename Key,
typename Convert, ArcFilter<GT> SA>
static inline
398 graph_to_tree_detail::build<GT, Key, SA>
401 Convert () (gtgt, ttgt);
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
C++20 concepts for the protocol shared by graph algorithms.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Stack of the frames of a depth-first search that does not recurse.
T & push(Args &&...args)
Builds a frame on top of the stack.
bool is_empty() const noexcept
Whether the stack has no frames.
T & top() noexcept
The top frame; the stack must not be empty.
void pop() noexcept
Destroys the top frame; the stack must not be empty.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Functor class to convert a tree graph to Tree_Node structure.
Tree_Node< Key > * operator()(GT &g, typename GT::Node *groot, Convert &&conv=Convert())
Convert a tree graph to Tree_Node structure.
void graph_to_tree(typename GT::Node *groot, Tree_Node< Key > *troot)
Graph_To_Tree_Node(SA __sa=SA())
Tree_Node< Key > * graph_to_tree(GT &g, typename GT::Node *groot, Convert &conv)
Determines whether a graph is acyclic (contains no cycles).
Forward declaration used by CRTP helpers before the full node definition.
void insert_rightmost_child(Tree_Node *p) noexcept
Inserts p as the rightmost child of this.
Tree_Node< Key > * graph_to_tree_node(GT &g, typename GT::Node *groot, SA sa=SA())
Convert a tree graph to a Tree_Node structure.
#define ALEPH_FLATTEN
[[gnu::flatten]], or nothing where it would only make the compilation slower.
void destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
void build(Tree_Node< Key > *troot, Convert &&convert, typename GT::Node *groot, Args &&... args)
Main namespace for Aleph-w library functions.
static void __graph_to_tree_node(GT &g, typename GT::Node *groot, Tree_Node< Key > *troot, const SA &sa)
void next_ne() noexcept(noexcept(std::declval< Aleph::const_iterator_t< HeadC > & >().next_ne()) and noexcept(std::declval< ZipIterator< TailC... > & >().next_ne()))
Advance all underlying iterators (unchecked variant).
Default filter for filtered iterators on arcs.
Filtered iterator of adjacent arcs of a node.
A node of the tree being built that waits for the one that it visits, its image in the tree,...
Node_Arc_Iterator< GT, SA > it
Frame(Tree_Node< Key > *t, typename GT::Arc *a, Args &&... args)
GT::Node * next_target() noexcept(noexcept(it.next_ne()))
void next_arc() noexcept(noexcept(it.next_ne()))
Stack of the frames of a depth-first search that does not recurse.
Generic graph and digraph implementations.
Utility algorithms and operations for graphs.
DAG (acyclic) graph testing.
General tree (n-ary tree) node.