Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_binNodeGenerators.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
73#ifndef TPL_BINNODEGENERATORS_H
74#define TPL_BINNODEGENERATORS_H
75
76#include <ah-generator.H>
77#include <tpl_arrayStack.H>
78#include <tpl_binNode.H>
79#include <tpl_binNodeUtils.H>
80
81namespace Aleph
82{
83
109template <class Node>
111{
112 if (root == Node::NullPtr)
113 co_return;
114
115 for (BinNodeInfixIterator<Node> it(root); it.has_curr(); it.next_ne())
116 {
117 Node *n = it.get_curr_ne();
118 co_yield n;
119 }
120}
121
139template <class Node>
141{
142 if (root == Node::NullPtr)
143 co_return;
144
145 for (BinNodePrefixIterator<Node> it(root); it.has_curr(); it.next_ne())
146 {
147 Node *n = it.get_curr_ne();
148 co_yield n;
149 }
150}
151
169template <class Node>
171{
172 if (root == Node::NullPtr)
173 co_return;
174
177 ArrayStack<Node *> stack(Node::MaxHeight);
178 Node *curr = root;
179 Node *last = Node::NullPtr;
180
181 // Iterative post-order: descend left spines; yield a node only after its
182 // right subtree root was the last node yielded.
183 while (curr != Node::NullPtr or not stack.is_empty())
184 {
185 while (curr != Node::NullPtr)
186 {
187 stack.push(curr);
188 curr = LLINK(curr);
189 }
190
191 Node *peek = stack.top();
192 Node *right = RLINK(peek);
193 if (right != Node::NullPtr and last != right)
194 {
195 curr = right;
196 continue;
197 }
198
199 last = stack.pop();
200 Node *n = last;
201 co_yield n;
202 }
203}
204
205} // end namespace Aleph
206
207#endif // TPL_BINNODEGENERATORS_H
Lazy sequence type (Aleph::Generator<T>) built on C++20 coroutines.
WeightedDigraph::Node Node
Stack implemented with simple dynamic array and with bounds verification.
T & top()
Return a modifiable reference to youngest element of stack (called the top)
bool is_empty() const noexcept
Return true if stack is empty.
T pop()
Extract the last more recently inserted element.
T & push(const T &data)
Push into stack a copy of data
Inorder iterator on the nodes of a binary tree.
bool has_curr() const noexcept
Return true the iterator has current node.
Preorder iterator on the nodes of a binary tree.
bool has_curr() const noexcept
Return true if iterator has current node.
Lazy, single-pass sequence of T values produced by a coroutine.
__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)
Definition gmpfrxx.h:4071
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
Aleph::Generator< Node * > lazy_in_order(Node *root)
Lazily traverse a binary tree in-order (left, node, right).
Aleph::Generator< Node * > lazy_post_order(Node *root)
Lazily traverse a binary tree post-order (left, right, node).
Aleph::Generator< Node * > lazy_pre_order(Node *root)
Lazily traverse a binary tree pre-order (node, left, right).
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
#define RLINK(i, n)
#define LLINK(i, n)
Stack implementations backed by dynamic or fixed arrays.
Utility functions for binary tree operations.
Basic binary tree node definitions.