43# ifndef GENERATE_TREE_H
44# define GENERATE_TREE_H
59 escaped.reserve(text.size());
61 for (
const char ch : text)
91 return to_str(p->get_key());
105 template <
typename Node,
class Write>
109 const size_t & current_level,
114 size_t level = current_level;
119 for (
size_t i = 0; i < level; ++i)
126 output <<
" \"" <<
Write()(p) <<
"\" " << std::endl;
128 if (
auto *child =
static_cast<Node *
>(p->get_left_child()))
131 <<
"Allocated size for deway array has been exceeded";
133 deway[level + 1] = 0;
141 while (p != node
and p->is_rightmost())
143 p =
static_cast<Node *
>(p->get_parent());
150 p =
static_cast<Node *
>(p->get_right_sibling());
189 template <
typename Node,
class Write = Dft_Write<Node>>
194 out <<
"Root \"" <<
Write()(
root) <<
"\" " << std::endl;
198 const auto deway = std::make_unique<int[]>(
size);
200 constexpr int level = 0;
204 Node *child =
static_cast<Node *
>(
root->get_left_child());
205 for (
int i = 0; child !=
nullptr;
206 i++, child =
static_cast<Node *
>(child->get_right_sibling()))
209 __generate_tree<Node, Write>(child,
deway.get(), level + 1,
235 template <
typename Node,
class Write = Dft_Write<Node>>
240 for (
int i = 0; tree !=
nullptr; i++, tree = tree->get_right_sibling())
241 generate_tree<Node, Write>(tree,
out, i);
268 template <
typename Node,
class Write>
271 out <<
"start-prefix ";
300 template <
typename Node,
class Write = Dft_Write<Node>>
303 out <<
"digraph Tree {" << std::endl;
304 out <<
" node [shape=circle, fontname=\"Helvetica\"];" << std::endl;
305 out <<
" edge [fontname=\"Helvetica\"];" << std::endl;
309 out <<
"}" << std::endl;
320 out <<
" \"" << p <<
"\" [label=\""
323 if (
auto * child =
static_cast<Node *
>(p->get_left_child()))
325 out <<
" \"" << p <<
"\" -> \"" << child <<
"\";" << std::endl;
341 auto * sibling =
static_cast<Node *
>(p->get_right_sibling());
342 out <<
" \"" << path.
top() <<
"\" -> \"" << sibling <<
"\";" << std::endl;
346 out <<
"}" << std::endl;
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
WeightedDigraph::Node Node
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.
Generic inorder traversal of a binary tree.
Generic preorder traversal of a binary tree.
void deway(Tree_Node< int > *p, int prefix[], const int &len, const size_t &dim)
Recursively compute and print Deway numbering for a tree node.
__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)
void generate_btree(Node *root, std::ostream &out)
Generate a binary tree specification for the btreepic drawing tool.
void generate_forest(Node *root, std::ostream &out)
Generate a forest specification for the ntreepic drawing tool.
void generate_tree(Node *root, std::ostream &out, const int &tree_number=0)
Generate a tree specification for the ntreepic drawing tool.
size_t compute_height(Node *root)
Computes the height of the tree root.
void generate_tree_graphviz(Node *root, std::ostream &out)
Generate a Graphviz DOT specification for a tree.
Main namespace for Aleph-w library functions.
constexpr size_t Max_Tree_Node_Depth
The depth of the trees that generate_tree() wrote before 7.3.2; it writes trees of any depth now.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
std::string escape_dot_label(const std::string &text)
and
Check uniqueness with explicit hash + equality functors.
std::string to_str(const double d)
Convert double to a std::string with maximum round-trip precision.
static void __generate_tree(Node *node, int deway[], const size_t ¤t_level, const size_t &size, std::ostream &output)
std::string operator()(Node *p)
Utility functions for binary tree operations.
Stack of the frames of a depth-first search that does not recurse.
General tree (n-ary tree) node.