33 #ifndef __H__UG__ntree_traversal__
34 #define __H__UG__ntree_traversal__
44 template <
class tree_t,
class traverser_t>
47 std::vector<size_t> nodes;
48 nodes.reserve(tree.num_nodes());
52 traverser.begin_traversal(tree);
55 while(curInd < (
int)nodes.size()){
56 size_t node = nodes[curInd];
57 int state = traverser.visit_up(tree, node);
60 size_t numChildren = tree.num_child_nodes(node);
61 const size_t* child = tree.child_node_ids(node);
62 for(
size_t i = 0; i < numChildren; ++i)
63 nodes.push_back(child[i]);
74 curInd = (int)nodes.size() - 1;
76 size_t node = nodes[curInd];
77 traverser.visit_down(tree, node);
81 traverser.end_traversal(tree);
84 template <
class tree_t,
class traverser_t>
88 int state = traverser.visit_up(tree, curNode);
91 size_t numChildren = tree.num_child_nodes(curNode);
92 const size_t* child = tree.child_node_ids(curNode);
93 for(
size_t i = 0; i < numChildren; ++i){
96 traverser.visit_down(tree, curNode);
102 traverser.visit_down(tree, curNode);
106 template <
class tree_t,
class traverser_t>
109 traverser.begin_traversal(tree);
111 traverser.end_traversal(tree);
TraversalStates
Definition: ntree_traversal.h:38
@ ABORT_TRAVERSAL
Definition: ntree_traversal.h:41
@ DONT_TRAVERSE_CHILDREN
Definition: ntree_traversal.h:39
@ TRAVERSE_CHILDREN
Definition: ntree_traversal.h:40
void TraverseDepthFirst(const tree_t &tree, traverser_t &traverser)
Definition: ntree_traversal.h:107
int TraverseDepthFirstRecursion(const tree_t &tree, traverser_t &traverser, int curNode)
Definition: ntree_traversal.h:86
void TraverseBreadthFirst(const tree_t &tree, traverser_t &traverser)
Definition: ntree_traversal.h:45