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 {
10 template <typename LEAF_CONTAINER, typename VALUE, uint64_t MAX_DEGREE>
12 {
13
14 public:
19
20 std::vector<SNode> _st;
21 uint64_t idx = 0;
22
23 using iterator_category = std::bidirectional_iterator_tag;
24 using difference_type = std::ptrdiff_t;
25
27 {
28 this->idx = UINT64_MAX;
29 }
30 /*
31 BPLeafForwardIterator(uint64_t leaf)
32 {
33 this->_st.push_back(SNode(NodePointer::build_leaf_pointer(leaf, -1), 0, false));
34 this->idx = 0;
35 }
36 */
37
39 {
40 if (_root != nullptr)
41 {
42 BASE_ITE::initialize_stack(this->_st, *_root);
43 this->idx = 0;
44 }
45 else
46 {
47 this->idx = UINT64_MAX;
48 }
49 }
50
55
56
57 uint64_t get_current_leaf_container_index() const
58 {
59 assert(this->_st.size() != 0);
60 SNode top = this->_st[this->_st.size() - 1];
61 return top.pointer.get_leaf_container_index();
62 }
63
64 bool is_end() const
65 {
66 return this->idx == UINT64_MAX;
67 }
68 void copy_to(BPLeafForwardIterator &item) const
69 {
70 item._st.clear();
71 for (auto &it : this->_st)
72 {
73 item._st.push_back(it.copy());
74 }
75 item.idx = this->idx;
76 }
77
79
83
84 uint64_t operator*() const
85 {
86 return this->get_current_leaf_container_index();
87 }
88
89 BPLeafForwardIterator &operator++()
90 {
91 while (true)
92 {
93 bool b = BASE_ITE::proceed(this->_st);
94 if(b){
95 SNode top = this->_st[this->_st.size() - 1];
96 if(top.pointer.is_leaf()){
97 this->idx++;
98 break;
99 }
100 }else{
101 this->idx = UINT64_MAX;
102 break;
103 }
104 }
105 return *this;
106 }
107 bool operator==(const BPLeafForwardIterator &other) const { return this->idx == other.idx; }
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
115 };
116 }
117}
The internal node of BPTree.
Definition bp_internal_node.hpp:16
A forward iterator for traversing the leaves of a BP-tree.
Definition bp_leaf_forward_iterator.hpp:12
A pointer to a node of BPTree.
Definition bp_node_pointer.hpp:15
The iterator of a post-order traversal on BPTree.
Definition bp_postorder_iterator.hpp:14
The item of the stack for traversing BPTree.
Definition stack_node.hpp:14