75#ifndef GENERATE_DF_TREE_H
76#define GENERATE_DF_TREE_H
126 template <AlephGraph GT>
132 std::ostringstream s;
162 return "(" + key.
label +
"," + std::to_string(key.
df) +
")";
179 return key.
label +
"," + std::to_string(key.
df) +
"," +
180 (key.
low >= 0 ? std::to_string(key.
low) : std::string(
"-"));
184 namespace df_tree_detail
187 template <AlephGraph GT,
class Node_Label, ArcFilter<GT> SA>
210 ~Guard() {
delete tp; }
249 Arc * a = f.
it.get_curr();
253 Node * t = f.
it.get_tgt_node();
287 parent_key.
low = std::min(parent_key.
low,
low);
309 root->get_key().low = -1;
314 for (
auto it =
tree_nodes.get_it(); it.has_curr(); it.next_ne())
315 delete it.get_curr().second;
340 for (
auto it =
arcs.get_it(); it.has_curr(); it.next_ne())
342 (void) numbers.
insert(it.get_curr().first, std::string());
343 (void) numbers.
insert(it.get_curr().second, std::string());
346 size_t missing = numbers.
size();
350 std::string number =
"0";
357 pair->second = number;
375 number.resize(path.
top().parent_length);
386 number += std::to_string(++level.
index);
444 template <AlephGraph GT,
class Node_Label = Dft_Df_Tree_Label<GT>,
445 ArcFilter<GT> SA = Dft_Show_Arc<GT>>
449 Node_Label node_label = Node_Label(), SA sa = SA())
452 <<
"build_df_low_tree(): g is a digraph";
454 <<
"build_df_low_tree(): src must be non-null";
456 non_tree_arcs.
empty();
458 (node_label, sa, non_tree_arcs).
build(src);
502 Node_Label node_label = Node_Label(), SA sa = SA())
505 std::unique_ptr<Df_Low_Tree_Node, df_tree_detail::Tree_Deleter>
root
508 generate_tree<Df_Low_Tree_Node, Write>(
root.get(),
out);
514 for (
auto it = non_tree_arcs.
get_it(); it.has_curr(); it.next_ne(), ++i)
517 out <<
"Dashed-Connexion " << numbers.
find(arc.first) <<
" "
518 << numbers.
find(arc.second) << (i % 2 == 0 ?
" L" :
" R") <<
'\n';
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
C++20 concepts for the protocol shared by graph algorithms.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
size_t size_t int32_t * out
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.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
void empty() noexcept
empty the list
Generic key-value map implemented on top of a binary search tree.
Pair * search(const Key &key) noexcept(nothrow_search)
Collect all keys.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Data & find(const Key &key)
Find the value associated with key.
const size_t & size() const
Returns the cardinality of the set.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Graph_Node< Node_Info > Node
The graph type.
Graph_Arc< Arc_Info > Arc
The node class type.
Forward declaration used by CRTP helpers before the full node definition.
Tree_Node * get_left_child() const noexcept
Returns the leftmost child of this.
constexpr bool is_rightmost() const noexcept
Returns true if this is the rightmost node among its siblings.
Tree_Node * get_right_sibling() const noexcept
Returns the right sibling of this.
void insert_rightmost_child(Tree_Node *p) noexcept
Inserts p as the rightmost child of this.
Tree_Node * get_parent() const noexcept
Returns the parent of this.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
Depth-first traversal that builds the tree of build_df_low_tree().
DynMapTree< Node *, Df_Low_Tree_Node * > tree_nodes
Df_Low_Builder(Node_Label &label, SA &filter, DynList< Df_Low_Non_Tree_Arc > &arcs)
Prepare a traversal that labels the nodes with label, sees only the arcs that filter accepts and appe...
Df_Low_Tree_Node * build(Node *src)
Build the tree from src; on an exception, free what it built.
Df_Low_Tree_Node * new_tree_node(Node *p)
DynList< Df_Low_Non_Tree_Arc > & non_tree_arcs
void visit(Node *src, Df_Low_Tree_Node *root)
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
bool is_digraph() const noexcept
Return true if the graph this is directed.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Tree visualization and output generation.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
DynArray< Graph::Arc * > arcs
Df_Low_Tree_Node * build_df_low_tree(const GT &g, typename GT::Node *src, DynList< Df_Low_Non_Tree_Arc > &non_tree_arcs, Node_Label node_label=Node_Label(), SA sa=SA())
Build the depth-first spanning tree of an undirected graph, with the df and low numbers of its nodes.
void write_df_low_tree(const GT &g, typename GT::Node *src, std::ostream &out, Node_Label node_label=Node_Label(), SA sa=SA())
Write, for ntreepic, the depth-first spanning tree of an undirected graph with the df and low numbers...
void destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
Singly linked list implementations with head-tail access.
void number_tree(Df_Low_Tree_Node *root, const DynList< Df_Low_Non_Tree_Arc > &arcs, DynMapTree< Df_Low_Tree_Node *, std::string > &numbers)
Give to each node that an arc of arcs names its Dewey number, as generate_tree() writes them.
Main namespace for Aleph-w library functions.
Tree_Node< Df_Low_Key > Df_Low_Tree_Node
Node of the depth-first tree that build_df_low_tree() returns.
Container2< typename Container1::Item_Type > filter(Container1 &container, Operation &operation)
Filter elements that satisfy operation.
static long & low(typename GT::Node *p)
Internal helper: low-link value stored directly in NODE_COOKIE(p).
std::pair< Df_Low_Tree_Node *, Df_Low_Tree_Node * > Df_Low_Non_Tree_Arc
Arc of the graph that is not in the depth-first tree.
and
Check uniqueness with explicit hash + equality functors.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
void next()
Advance all underlying iterators (bounds-checked).
Key of a node of a depth-first tree with df and low numbers.
long df
Depth-first number: 0 for the start node.
std::string label
Label of the graph node.
long low
Low number; -1 for the start node, which has none.
Default label of a graph node: its information, written with operator <<.
std::string operator()(typename GT::Node *p) const
Return the information of p, written with operator <<.
Default filter for filtered iterators on arcs.
Filtered iterator of adjacent arcs of a node.
Writer for generate_tree() that shows the label and the df number of each node, as (label,...
std::string operator()(Df_Low_Tree_Node *p) const
Return (label,df) for p.
Writer for generate_tree() that shows the label of each node.
std::string operator()(Df_Low_Tree_Node *p) const
Return the label of p.
Writer for generate_tree() that shows the label, the df and the low numbers of each node,...
std::string operator()(Df_Low_Tree_Node *p) const
Return label,df,low for p, or label,df,- if it has no low number.
A level of the path that number_tree() follows: the length of the Dewey number of the parent,...
Frame(Node *n, Df_Low_Tree_Node *t, Arc *a, SA &filter)
Node_Arc_Iterator< GT, SA > it
Deleter that frees a whole tree.
void operator()(Df_Low_Tree_Node *root) const
Free root and every node below it.
Stack of the frames of a depth-first search that does not recurse.
Dynamic key-value map based on balanced binary search trees.
Generic graph and digraph implementations.
General tree (n-ary tree) node.