| 88 | /// subtree should be skipped. |
| 89 | template <typename PreVisitor, typename PostVisitor> |
| 90 | Status Visit(PreVisitor&& pre, PostVisitor&& post) const { |
| 91 | std::vector<Ref> parent_stack; |
| 92 | |
| 93 | for (int i = 0; i < size_; ++i) { |
| 94 | Ref ref = {this, i}; |
| 95 | |
| 96 | while (parent_stack.size() > 0) { |
| 97 | if (parent_stack.back().IsAncestorOf(ref)) break; |
| 98 | |
| 99 | post(parent_stack.back()); |
| 100 | parent_stack.pop_back(); |
| 101 | } |
| 102 | |
| 103 | ARROW_ASSIGN_OR_RAISE(bool visit_subtree, pre(ref)); |
| 104 | |
| 105 | if (!visit_subtree) { |
| 106 | // skip descendants |
| 107 | i += ref.num_descendants(); |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | parent_stack.push_back(ref); |
| 112 | } |
| 113 | |
| 114 | return Status::OK(); |
| 115 | } |
| 116 | |
| 117 | Ref operator[](int i) const { return Ref{this, i}; } |
| 118 | |