64 template <
class,
class>
71 using offset_type =
typename Tree::offset_type;
72 using depth_type =
typename Tree::depth_type;
81 using iterator_category = std::forward_iterator_tag;
82 using difference_type = std::ptrdiff_t;
83 using value_type = Node;
84 using reference = value_type
const&;
85 using pointer = value_type
const*;
94 , start_(tree->
depth(node))
95 , nextNode(nextNodeFun(only_exists, early_stopping))
97 if (only_exists && !tree_->exists(cur_)) {
102 Filter::init(pred_, *tree_);
104 if (!Filter::returnable(pred_, *tree_, cur_)) {
106 cur_ = next<true, false>(*tree_, pred_, cur_, start_);
108 cur_ = next<false, false>(*tree_, pred_, cur_, start_);
115 template <
class Predicate2>
120 , start_(other.start_)
121 , nextNode(other.nextNode)
127 cur_ = nextNode(*tree_, pred_, cur_, start_);
138 reference operator*()
const {
return cur_; }
140 pointer operator->()
const {
return &cur_; }
142 template <
class Predicate2>
145 return cur_.code == other.cur_.code;
148 template <
class Predicate2>
151 return !(*
this == other);
155 [[nodiscard]]
static auto nextNodeFun(
bool only_exists,
bool early_stopping)
157 if (only_exists && early_stopping) {
158 return &TreeQueryIterator::next<true, true>;
159 }
else if (only_exists && !early_stopping) {
160 return &TreeQueryIterator::next<true, false>;
161 }
else if (!only_exists && early_stopping) {
162 return &TreeQueryIterator::next<false, true>;
164 return &TreeQueryIterator::next<false, false>;
168 template <
bool OnlyExists>
169 [[nodiscard]]
static bool traversable(
Tree const& tree, Predicate
const& pred,
172 if constexpr (OnlyExists) {
173 return tree.
isParent(node.index) && Filter::traversable(pred, tree, node);
175 return 0 < node.code.depth() && Filter::traversable(pred, tree, node);
179 template <
bool OnlyExists>
180 [[nodiscard]]
static Node firstborn(
Tree const& tree, Node node)
182 node.code = node.code.firstborn();
183 if constexpr (OnlyExists) {
184 node.index = tree.
child(node.index, 0);
185 }
else if (tree.
isParent(node.index)) {
186 node.index = tree.
child(node.index, 0);
191 template <
bool OnlyExists,
bool EarlyStopping>
192 [[nodiscard]]
static Node next(
Tree const& tree, Predicate
const& pred, Node node,
195 if constexpr (!EarlyStopping) {
198 while (traversable<OnlyExists>(tree, pred, node)) {
199 node = firstborn<OnlyExists>(tree, node);
201 if (Filter::returnable(pred, tree, node)) {
208 while (BF - 1 <= node.code.offset()) {
209 node.code = node.code.parent();
212 if (start <= node.code.depth()) {
216 node.code = node.code.nextSibling();
217 node.index = tree.ancestor(node.index, node.code.depth());
219 if constexpr (OnlyExists) {
222 node.index.offset += node.code.depth() == tree.
depth(node.index) ? 1 : 0;
225 if (Filter::returnable(pred, tree, node)) {
229 while (traversable<OnlyExists>(tree, pred, node)) {
230 node = firstborn<OnlyExists>(tree, node);
232 if (Filter::returnable(pred, tree, node)) {
247 decltype(&TreeQueryIterator::next<true, true>) nextNode;