b-tree-plus-alpha
Loading...
Searching...
No Matches
bp_leaf_forward_iterator.hpp
1#pragma once
2#include "./bp_postorder_iterator.hpp"
3namespace stool
4{
5 namespace bptree
6 {
11 template <typename LEAF_CONTAINER, typename VALUE, uint64_t MAX_DEGREE, bool USE_PSUM>
13 {
14
15 public:
20
21 std::vector<SNode> _st;
22 uint64_t idx = 0;
23
24 using iterator_category = std::bidirectional_iterator_tag;
25 using difference_type = std::ptrdiff_t;
26
28 {
29 this->idx = UINT64_MAX;
30 }
31 /*
32 BPLeafForwardIterator(uint64_t leaf)
33 {
34 this->_st.push_back(SNode(NodePointer::build_leaf_pointer(leaf, -1), 0, false));
35 this->idx = 0;
36 }
37 */
38
40 {
41 if (_root != nullptr)
42 {
43 BASE_ITE::initialize_stack(this->_st, *_root);
44 this->idx = 0;
45 }
46 else
47 {
48 this->idx = UINT64_MAX;
49 }
50 }
51
56
57
58 uint64_t get_current_leaf_container_index() const
59 {
60 assert(this->_st.size() != 0);
61 SNode top = this->_st[this->_st.size() - 1];
62 return top.pointer.get_leaf_container_index();
63 }
64
65 bool is_end() const
66 {
67 return this->idx == UINT64_MAX;
68 }
69 void copy_to(BPLeafForwardIterator &item) const
70 {
71 item._st.clear();
72 for (auto &it : this->_st)
73 {
74 item._st.push_back(it.copy());
75 }
76 item.idx = this->idx;
77 }
78
80
84
85 uint64_t operator*() const
86 {
87 return this->get_current_leaf_container_index();
88 }
89
90 BPLeafForwardIterator &operator++()
91 {
92 while (true)
93 {
94 bool b = BASE_ITE::proceed(this->_st);
95 if(b){
96 SNode top = this->_st[this->_st.size() - 1];
97 if(top.pointer.is_leaf()){
98 this->idx++;
99 break;
100 }
101 }else{
102 this->idx = UINT64_MAX;
103 break;
104 }
105 }
106 return *this;
107 }
108 bool operator==(const BPLeafForwardIterator &other) const { return this->idx == other.idx; }
109 bool operator!=(const BPLeafForwardIterator &other) const { return this->idx != other.idx; }
110 bool operator<(const BPLeafForwardIterator &other) const { return this->idx < other.idx; }
111 bool operator>(const BPLeafForwardIterator &other) const { return this->idx > other.idx; }
112 bool operator<=(const BPLeafForwardIterator &other) const { return this->idx <= other.idx; }
113 bool operator>=(const BPLeafForwardIterator &other) const { return this->idx >= other.idx; }
114
116 };
117 }
118}
The internal node of BPTree [Unchecked AI's Comment].
Definition bp_internal_node.hpp:15
A forward iterator for traversing the leaves of a BP-tree. [Unchecked AI's Comment].
Definition bp_leaf_forward_iterator.hpp:13
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 item of the stack for traversing BPTree [Unchecked AI's Comment].
Definition stack_node.hpp:13