38# include <gtest/gtest.h>
160 p5.insert_left_sibling(&p4);
210 { return p->get_key() == ++k; }));
241 p0.insert_leftmost_child(&p1);
270 for (
auto it =
root->get_it(); it.has_curr(); it.next(),
itl.next(), ++
k)
295 return p->get_key() == i++;
305 for (
Pit it{It(
root), It(clone)}; it.has_curr(); it.next())
308 ASSERT_EQ(p.first->get_key(), p.second->get_key());
322 ASSERT_TRUE(
root.traverse([&
k] (
auto p) { k++; return p->get_key() == 5; }));
331 auto *
t1 =
new Node(
"root");
332 t1->insert_rightmost_child(
new Node(
"A"));
333 t1->insert_rightmost_child(
new Node(
"B"));
335 auto *
t2 =
new Node(
"ROOT");
336 t2->insert_rightmost_child(
new Node(
"a"));
337 t2->insert_rightmost_child(
new Node(
"b"));
339 auto nocase = [] (
const std::string & a,
const std::string & b)
341 if (a.size() != b.size())
343 for (
size_t i = 0; i < a.size(); ++i)
344 if (std::tolower(
static_cast<unsigned char>(a[i])) !=
345 std::tolower(
static_cast<unsigned char>(b[i])))
362 bool r = p->get_key() == it.get_curr();
396 t1->insert_tree_to_right(
t3);
397 t1->insert_tree_to_right(
t2);
414 DynList<int> l = { 0, 1, 2, 3, 4, 5, 31, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
415 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
416 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43 };
419 t->level_traverse([&
order] (
auto p) {
order.
append(p->get_key());
return true; });
String manipulation utilities.
Zip iterators and functional operations for multiple containers.
WeightedDigraph::Node Node
constexpr bool is_empty() const noexcept
Return true if this (as header node) is empty.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
size_t size() const noexcept
Count the number of elements of the list.
Iterator that zips two other iterators.
auto get_curr() const
Get current pair (bounds-checked).
Iterator over the children of this.
void reset_first() noexcept
bool has_curr() const noexcept
Tree_Node * get_curr() const
constexpr bool is_leftmost() const noexcept
Returns true if this is the leftmost node among its siblings.
bool traverse(Operation op)
Preorder traversal over all nodes executing op.
Dlink * get_sibling_list() noexcept
Tree_Node * get_left_sibling() const noexcept
Returns the left sibling of this.
constexpr bool is_root() const noexcept
Returns true if this is the root of the general tree.
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_child(const size_t i) const noexcept
Returns the i-th child of this.
void insert_leftmost_child(Tree_Node *p) noexcept
Inserts p as the leftmost child of this.
constexpr bool is_leaf() const noexcept
Returns true if this is a leaf node.
Dlink * get_child_list() noexcept
Tree_Node * get_right_sibling() const noexcept
Returns the right sibling of this.
Tree_Node * get_left_tree() const noexcept
Returns the tree to the left of this.
void insert_rightmost_child(Tree_Node *p) noexcept
Inserts p as the rightmost child of this.
Tree_Node * get_right_tree() const noexcept
Returns the tree to the right of this.
Tree_Node * get_parent() const noexcept
Returns the parent of this.
Container< Tree_Node * > children_nodes() const
Returns a list with the child nodes of this.
Tree_Node * get_right_child() const noexcept
Returns the rightmost child of this.
void insert_right_sibling(Tree_Node *p) noexcept
Inserts p as the right sibling of this.
Container< T > children() const
Returns a list with the contents of the children of this.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
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 destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
bool are_tree_equal(Node *t1, Node *t2, Eq &eq)
Returns true if t1 is equal to t2.
void destroy_forest(Node *root)
Destroys (frees memory) the forest whose first tree is root.
Node * search_deway(Node *root, const typename Node::key_type &key, int deway[], const size_t &size, size_t &n)
Searches key in a forest and computes the Dewey number of the node containing the key.
Main namespace for Aleph-w library functions.
void zip_for_each(Op &&op, const Cs &... cs)
Apply op to every zipped tuple.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
bool traverse(Node *root, Op op)
static void clone_tree(Node *src, Node *tgt)
std::ostream & join(const C &c, const std::string &sep, std::ostream &out)
Join elements of an Aleph-style container into a stream.
DynList< T > maps(const C &c, Op op)
Classic map operation.
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
General tree (n-ary tree) node.
TEST_F(Simple_Tree, Iterators)