69 using offset_type =
typename Tree::offset_type;
70 using depth_type =
typename Tree::depth_type;
77 using iterator_category = std::forward_iterator_tag;
78 using difference_type = std::ptrdiff_t;
79 using value_type = Node;
80 using reference = value_type
const&;
81 using pointer = value_type
const*;
85 TreeIterator(
Tree const* tree, Node node,
bool only_leaves,
bool only_exists)
88 , start_(tree->
depth(node))
89 , nextNode(nextNodeFun(only_leaves, only_exists))
91 if (only_exists && !tree_->exists(cur_)) {
93 }
else if (only_leaves && tree_->
isParent(node.index)) {
94 cur_ = nextNode(*tree_, cur_, start_);
100 cur_ = nextNode(*tree_, cur_, start_);
111 reference operator*()
const {
return cur_; }
113 pointer operator->()
const {
return &cur_; }
117 return lhs.cur_.code == rhs.cur_.code;
122 return !(lhs == rhs);
126 [[nodiscard]]
static auto nextNodeFun(
bool only_leaves,
bool only_exists)
128 if (only_leaves && only_exists) {
129 return &TreeIterator::next<true, true>;
130 }
else if (only_leaves && !only_exists) {
131 return &TreeIterator::next<true, false>;
132 }
else if (!only_leaves && only_exists) {
133 return &TreeIterator::next<false, true>;
135 return &TreeIterator::next<false, false>;
139 template <
bool OnlyLeaves,
bool OnlyExists>
140 [[nodiscard]]
static Node next(
Tree const& tree, Node node, depth_type start)
142 if constexpr (!OnlyLeaves) {
145 if constexpr (OnlyExists) {
147 node.code = node.code.firstborn();
148 node.index = tree.
child(node.index, 0);
152 if (0 < node.code.depth()) {
153 node.code = node.code.firstborn();
155 node.index = tree.
child(node.index, 0);
164 while (BF - 1 <= node.code.offset()) {
165 node.code = node.code.parent();
168 if (start <= node.code.depth()) {
172 node.code = node.code.nextSibling();
173 node.index = tree.ancestor(node.index, node.code.depth());
175 if constexpr (OnlyExists) {
178 node.index.offset += node.code.depth() == tree.
depth(node.index) ? 1 : 0;
181 if constexpr (OnlyLeaves) {
185 node.index = tree.
child(node.index, 0);
188 if constexpr (OnlyExists) {
189 node.code.setDepth(tree.
depth(node.index));
191 node.code.setDepth(0);
204 decltype(&TreeIterator::next<true, true>) nextNode;
static constexpr offset_type branchingFactor() noexcept
Returns the branching factor of the tree (i.e., 2 = binary tree, 4 = quadtree, 8 = octree,...