6#ifndef ALTINTEGRATION_TREE_ALGO_HPP
7#define ALTINTEGRATION_TREE_ALGO_HPP
11#include <unordered_set>
13#include "block_index.hpp"
18template <
typename Block>
24 std::unordered_set<index_t*> set;
25 std::stack<index_t*> stack;
27 while (!stack.empty()) {
28 auto* item = stack.top();
29 if (set.count(item) > 0) {
33 for (
auto* next : item->pnext) {
34 if (shouldVisit(*next)) {
44template <
typename Block>
54 auto copy = index.
pnext;
55 for (
auto* pnext : copy) {
56 VBK_ASSERT(pnext !=
nullptr);
62template <
typename Block>
66 for (
auto* pnext : index.
pnext) {
67 VBK_ASSERT(pnext !=
nullptr);
68 if (shouldContinue(*pnext)) {
78template <
typename Block>
81 std::vector<index_t*> ret{};
82 forEachNodePreorder<Block>(index, [&ret](index_t& next) ->
bool {
83 if (!next.isValid()) {
89 if (next.isValidTip()) {
105template <
typename Block>
110 std::vector<index_t*> ret{};
111 for (
auto* tip : tips) {
112 auto* ancestor = tip->
getAncestor(index.getHeight());
113 if (ancestor == &index) {
void forEachNodePostorder(BlockIndex< Block > &index, const std::function< void(BlockIndex< Block > &)> &visit, const std::function< bool(BlockIndex< Block > &)> &shouldVisit)
Postorder tree traversal algorithm.
std::vector< BlockIndex< Block > * > findValidTips(BlockIndex< Block > &index)
Find all tips after given block, including given block.
void forEachNodePreorder(BlockIndex< Block > &index, const std::function< bool(BlockIndex< Block > &)> &visit)
iterate across all subtrees starting (and including) given 'index'
void forEachNextNodePreorder(BlockIndex< Block > &index, const std::function< bool(BlockIndex< Block > &)> &shouldContinue)
iterate across all subtrees starting (and excluding) given 'index'
std::set< BlockIndex * > pnext
(memory only) a set of pointers for forward iteration
const BlockIndex * getAncestor(height_t _height) const