b-tree-plus-alpha
Loading...
Searching...
No Matches
bp_value_forward_iterator.hpp
1#pragma once
2#include "./bp_postorder_iterator.hpp"
3
4
5
6namespace stool
7{
8 namespace bptree
9 {
14 template <typename LEAF_CONTAINER, typename VALUE, uint64_t MAX_DEGREE, bool USE_PSUM>
16 {
17 private:
18 void sub_proceed()
19 {
20 while (!this->node_it.is_end() && !this->node_it.get_current_node().is_leaf())
21 {
22 ++this->node_it;
23
24 }
25
26 if (this->node_it.is_end())
27 {
28 this->tmp_values.clear();
29 this->node_it.idx = UINT64_MAX;
30 this->tmp_idx = UINT32_MAX;
31 }
32 else
33 {
34
35 this->tmp_values.clear();
36 LEAF_CONTAINER &cont = (*this->ref)[this->node_it.get_current_node().get_leaf_container_index()];
37
38 for (const VALUE it : cont)
39 {
40 this->tmp_values.push_back(it);
41 }
42 this->tmp_idx = 0;
43 }
44
45 }
46
47 public:
52
53 NodeIterator node_it;
54 std::vector<uint64_t> tmp_values;
55 std::vector<LEAF_CONTAINER> *ref = nullptr;
56 uint32_t tmp_idx;
57
58 using iterator_category = std::bidirectional_iterator_tag;
59 using difference_type = std::ptrdiff_t;
60
61 BPValueForwardIterator(NodeIterator *_root, const std::vector<LEAF_CONTAINER> *_ref)
62 {
63 this->tmp_values.clear();
64 this->tmp_idx = 0;
65 this->ref = const_cast<std::vector<LEAF_CONTAINER> *>(_ref);
66 if (_root != nullptr)
67 {
68 _root->copy_to(this->node_it);
69 if (this->node_it.is_end())
70 {
71 this->node_it.idx = UINT64_MAX;
72 this->tmp_idx = UINT32_MAX;
73 }
74 else
75 {
76 this->sub_proceed();
77 }
78 }
79 else
80 {
81 this->node_it.idx = UINT64_MAX;
82 this->tmp_idx = UINT32_MAX;
83 }
84 }
85 int compare(const BPValueForwardIterator &other) const
86 {
87 if (this->node_it.idx != other.node_it.idx)
88 {
89 if (this->node_it.idx < other.node_it.idx)
90 {
91 return -1;
92 }
93 else
94 {
95 return 1;
96 }
97 }
98 else
99 {
100 if (this->tmp_idx != other.tmp_idx)
101 {
102 if (this->tmp_idx < other.tmp_idx)
103 {
104 return -1;
105 }
106 else
107 {
108 return 1;
109 }
110 }
111 else
112 {
113 return 0;
114 }
115 }
116 }
117
118 VALUE operator*() const
119 {
120 if (this->node_it.is_end())
121 {
122 throw std::runtime_error("Error:BPValueForwardIterator");
123 }
124 else
125 {
126 return this->tmp_values[this->tmp_idx];
127 }
128 }
129 bool is_end() const
130 {
131 return this->tmp_idx == UINT32_MAX;
132 }
133
134 BPValueForwardIterator &operator++()
135 {
136 if (this->tmp_idx + 1 < this->tmp_values.size())
137 {
138 this->tmp_idx++;
139 }
140 else if (this->tmp_idx + 1 == this->tmp_values.size())
141 {
142 ++this->node_it;
143 this->sub_proceed();
144 }
145 else
146 {
147 throw std::runtime_error("Error:BPValueForwardIterator");
148 }
149 return *this;
150 }
151
152 bool operator==(const BPValueForwardIterator &other) const { return this->compare(other) == 0; }
153 bool operator!=(const BPValueForwardIterator &other) const { return this->compare(other) != 0; }
154 bool operator<(const BPValueForwardIterator &other) const { return this->compare(other) < 0; }
155 bool operator>(const BPValueForwardIterator &other) const { return this->compare(other) > 0; }
156 bool operator<=(const BPValueForwardIterator &other) const { return this->compare(other) <= 0; }
157 bool operator>=(const BPValueForwardIterator &other) const { return this->compare(other) >= 0; }
158 };
159 }
160}
The internal node of BPTree [Unchecked AI's Comment].
Definition bp_internal_node.hpp:15
A pointer to a node of BPTree [Unchecked AI's Comment].
Definition bp_node_pointer.hpp:14
The iterator of a post-order traversal on BPTree [Unchecked AI's Comment].
Definition bp_postorder_iterator.hpp:13
The forward iterator of the values stored in BPTree [Unchecked AI's Comment].
Definition bp_value_forward_iterator.hpp:16
The item of the stack for traversing BPTree [Unchecked AI's Comment].
Definition stack_node.hpp:13