10#ifndef PBAT_COMMON_NARYTREETRAVERSAL_H
11#define PBAT_COMMON_NARYTREETRAVERSAL_H
16#include "pbat/HostDevice.h"
37template <
class FVisit,
class FChild,
class TIndex = Index, auto N = 2, auto kStackDepth = 64>
60template <
class FVisit,
class FChild,
class TIndex = Index, auto N = 2, auto kStackDepth = 64>
64template <
class FVisit,
class FChild,
class TIndex, auto N, auto kStackDepth>
69 while (not dfs.IsEmpty())
71 TIndex
const node = dfs.Pop();
76 auto const child = fChild.template operator()<N - i - 1>(node);
83template <
class FVisit,
class FChild,
class TIndex, auto N, auto kStackDepth>
89 bool bChildrenVisited;
92 dfs.
Push({root,
false});
93 while (not dfs.IsEmpty())
95 auto const visit = dfs.Top();
97 if (visit.bChildrenVisited)
103 dfs.Push({visit.node,
true});
105 auto const child = fChild.template operator()<N - i - 1>(visit.node);
107 dfs.Push({child,
false});
Fixed-size stack implementation.
Definition Stack.h:26
PBAT_HOST_DEVICE void Push(T value)
Add element to the stack.
Definition Stack.h:37
Fixed-size stack implementation usable in both host and device code.
Common functionality.
Definition ArgSort.h:20
PBAT_HOST_DEVICE void TraverseNAryTreePseudoPreOrder(FVisit fVisit, FChild fChild, TIndex root=0)
Pre-order traversal over an n-ary tree starting from root.
Definition NAryTreeTraversal.h:65
PBAT_HOST_DEVICE void TraverseNAryTreePseudoPostOrder(FVisit fVisit, FChild fChild, TIndex root=0)
Post-order traversal over an n-ary tree starting from root.
Definition NAryTreeTraversal.h:84
constexpr void ForRange(F &&f)
Compile-time for loop over a range of values.
Definition ConstexprFor.h:55