b-tree-plus-alpha
Loading...
Searching...
No Matches
dynamic_sequence64.hpp
Go to the documentation of this file.
1
6#pragma once
7#include "../bp_tree/bp_tree.hpp"
8
9namespace stool
10{
11 namespace bptree
12 {
20 public:
23 private:
24 Tree tree;
25
26 public:
32 {
33 return this->tree.get_value_forward_iterator_begin();
34 }
40 {
41 return this->tree.get_value_forward_iterator_end();
42 }
43
48 {
49 this->tree.initialize();
50 }
56 {
57 this->tree.swap(item.tree);
58 }
59
60 DynamicSequence64 &operator=(const DynamicSequence64 &) = delete;
63
64 public:
65
69 void clear()
70 {
71 this->tree.clear();
72 }
76 void verify() const
77 {
78 this->tree.verify();
79 }
85 {
86 return this->tree;
87 }
93 {
94 return this->tree.get_max_degree_of_internal_node();
95 }
96
103 static DynamicSequence64 build(const std::vector<uint64_t> &items)
104 {
106 r.tree.initialize();
107 r.tree.build(items);
108 return r;
109 }
110
116 {
117 return this->tree.size();
118 }
124 {
125 this->tree.push_back(value);
126 }
132 {
133 this->tree.push_front(value);
134 }
135
142 {
143 this->tree.insert(pos, value, value);
144 }
150 {
151 this->tree.remove(pos);
152 }
157 std::vector<uint64_t> to_vector() const
158 {
159 return this->tree.to_value_vector();
160 }
161
168 {
169 return this->tree.at(pos);
170 }
177 uint64_t v = this->at(pos);
178 if(v < value){
179 this->increment(pos, value - v);
180 }else if(v > value){
181 this->decrement(pos, v - value);
182 }
183 }
190 {
191 this->tree.increment(i, delta);
192 }
199 {
200 this->tree.increment(i, -delta);
201 }
202
207 static std::string name()
208 {
209 std::string s;
210 s += "SPSI(";
211 s += VLCDeque::name();
212 s += ")";
213 return s;
214 }
219 void push_many(const std::vector<uint64_t> &items)
220 {
221 this->tree.push_many(items);
222 }
228 {
229 return this->tree.size_in_bytes();
230 }
236 std::vector<std::string> get_memory_usage_info(int message_paragraph = stool::Message::SHOW_MESSAGE) const
237 {
238 std::vector<std::string> log1 = this->tree.get_memory_usage_info(message_paragraph+1);
239
240 std::vector<std::string> r;
241 r.push_back(stool::Message::get_paragraph_string(message_paragraph) + "=DynamicSequence64: " + std::to_string(this->size_in_bytes()) + " bytes =");
242 for (std::string &s : log1)
243 {
244 r.push_back(s);
245 }
246 r.push_back(stool::Message::get_paragraph_string(message_paragraph) + "==");
247 return r;
248 }
253 void print_memory_usage(int message_paragraph = stool::Message::SHOW_MESSAGE) const
254 {
255 std::vector<std::string> log = this->get_memory_usage_info(message_paragraph);
256 for (std::string &s : log)
257 {
258 std::cout << s << std::endl;
259 }
260 }
265 void print_statistics(int message_paragraph = stool::Message::SHOW_MESSAGE) const
266 {
267 std::cout << stool::Message::get_paragraph_string(message_paragraph) << "Statistics(DynamicSequence64):" << std::endl;
268 this->tree.print_statistics(message_paragraph + 1);
269 std::cout << stool::Message::get_paragraph_string(message_paragraph) << "[END]" << std::endl;
270 }
271
278 static void save(DynamicSequence64 &item, std::vector<uint8_t> &output, uint64_t &pos)
279 {
280 item.tree.save(output, pos);
281 }
287 static void save(DynamicSequence64 &item, std::ofstream &os)
288 {
289 item.tree.save(os);
290 }
291
298 static DynamicSequence64 build_from_data(const std::vector<uint8_t> &data, uint64_t &pos)
299 {
301 r.tree.build_from_data(data, pos);
302 return r;
303 }
304
310 static DynamicSequence64 build_from_data(std::ifstream &ifs)
311 {
313 r.tree.build_from_data(ifs);
314 return r;
315 }
322 {
323 return this->tree.at(n);
324 }
329 std::string to_string() const
330 {
331 std::stringstream ss;
332 auto vec = this->to_vector();
333 ss << stool::DebugPrinter::to_integer_string(vec);
334 return ss.str();
335 }
336
340 void print() const
341 {
342 auto vec = this->to_vector();
343 std::cout << "================== SPSI ==================" << std::endl;
344 stool::DebugPrinter::print_integers(vec, "values");
345
346 std::cout << "================== SPSI[END] =============" << std::endl;
347 }
348
349
350 };
351 }
352}
An implementation of B+-tree.
Definition bp_tree.hpp:24
void swap(BPTree &_tree, bool swap_linked_tree)
Swaps the contents of this B+ tree with another B+ tree.
Definition bp_tree.hpp:178
VALUE at(uint64_t pos) const
Returns the value at position pos in the B+ tree.
Definition bp_tree.hpp:574
void initialize()
Initializes the B+ tree with specified maximum degrees for internal nodes and leaf nodes.
Definition bp_tree.hpp:150
void push_many(std::vector< LEAF_CONTAINER > &containers)
Pushes multiple leaf containers into the B+ tree.
Definition bp_tree.hpp:1976
void print_statistics(int message_paragraph=stool::Message::SHOW_MESSAGE) const
Prints statistical information about the B+ tree.
Definition bp_tree.hpp:3037
void increment(uint64_t i, int64_t delta)
Increments a value at a given position in the B+ tree.
Definition bp_tree.hpp:2410
std::vector< VALUE > to_value_vector() const
Converts the B+ tree to a vector of values.
Definition bp_tree.hpp:685
uint64_t size() const
Return the number of values stored in this tree.
Definition bp_tree.hpp:316
void build(const std::vector< VALUE > &_values)
Builds a complete B+ tree from a vector of values.
Definition bp_tree.hpp:2857
ValueForwardIterator get_value_forward_iterator_begin() const
Returns an iterator pointing to the first value in forward traversal.
Definition bp_tree.hpp:404
ValueForwardIterator get_value_forward_iterator_end() const
Returns an iterator pointing to the end of forward value traversal.
Definition bp_tree.hpp:423
void push_back(VALUE value)
Pushes a single value to the B+ tree.
Definition bp_tree.hpp:1849
void remove(uint64_t pos)
Removes a value at a specific position in the B+ tree.
Definition bp_tree.hpp:2086
void save(std::vector< uint8_t > &output, uint64_t &pos)
Saves the B+ tree structure to a byte vector.
Definition bp_tree.hpp:2912
void push_front(VALUE value)
Inserts a value at the front of the B+ tree.
Definition bp_tree.hpp:1866
uint64_t get_max_degree_of_internal_node() const
Return the max degree of this tree. The number of children of every internal node does not exceed the...
Definition bp_tree.hpp:278
void clear()
Clears all contents of the B+ tree and resets it to an empty state.
Definition bp_tree.hpp:219
void build_from_data(const std::vector< uint8_t > &data, uint64_t &pos)
Builds a B+ tree from serialized data in a byte vector.
Definition bp_tree.hpp:2968
uint64_t size_in_bytes() const
Returns the total memory size of the B+ tree.
Definition bp_tree.hpp:931
bool verify() const
Verifies the integrity of the B+ tree.
Definition bp_tree.hpp:788
void insert(uint64_t pos, VALUE value, uint64_t sum_delta)
Inserts a value at a specific position in the B+ tree.
Definition bp_tree.hpp:2120
std::vector< std::string > get_memory_usage_info(int message_paragraph=stool::Message::SHOW_MESSAGE) const
Returns a vector of strings containing memory usage information about the B+ tree.
Definition bp_tree.hpp:1068
A dynamic data structure that maintains a sequence of 64-bit non-negative integers.
Definition dynamic_sequence64.hpp:19
static void save(DynamicSequence64 &item, std::vector< uint8_t > &output, uint64_t &pos)
Saves the sequence to a vector of bytes.
Definition dynamic_sequence64.hpp:278
std::vector< std::string > get_memory_usage_info(int message_paragraph=stool::Message::SHOW_MESSAGE) const
Returns information about the memory usage of the sequence.
Definition dynamic_sequence64.hpp:236
void print_memory_usage(int message_paragraph=stool::Message::SHOW_MESSAGE) const
Prints the memory usage of the sequence.
Definition dynamic_sequence64.hpp:253
DynamicSequence64()
Default constructor initializes the tree with a default degree.
Definition dynamic_sequence64.hpp:47
uint64_t size_in_bytes() const
Returns the size of the sequence in bytes.
Definition dynamic_sequence64.hpp:227
void print_statistics(int message_paragraph=stool::Message::SHOW_MESSAGE) const
Prints statistics about the sequence.
Definition dynamic_sequence64.hpp:265
void swap(DynamicSequence64 &item)
Swaps the contents of this sequence with another.
Definition dynamic_sequence64.hpp:55
void push_front(int64_t value)
Adds an element to the beginning of the sequence.
Definition dynamic_sequence64.hpp:131
void print() const
Prints the sequence to the console.
Definition dynamic_sequence64.hpp:340
Tree::ValueForwardIterator end() const
Returns an iterator to the end of the sequence.
Definition dynamic_sequence64.hpp:39
void push_back(int64_t value)
Adds an element to the end of the sequence.
Definition dynamic_sequence64.hpp:123
std::vector< uint64_t > to_vector() const
Converts the sequence to a vector.
Definition dynamic_sequence64.hpp:157
void clear()
Clears all elements from the sequence.
Definition dynamic_sequence64.hpp:69
void increment(uint64_t i, int64_t delta)
Increments the value at a specified position by a given delta.
Definition dynamic_sequence64.hpp:189
void set_value(uint64_t pos, uint64_t value)
Sets the value at a specified position in the sequence.
Definition dynamic_sequence64.hpp:176
uint64_t get_degree() const
Returns the degree of the tree.
Definition dynamic_sequence64.hpp:92
static std::string name()
Returns the name of the sequence.
Definition dynamic_sequence64.hpp:207
void remove(uint64_t pos)
Removes the element at a specified position from the sequence.
Definition dynamic_sequence64.hpp:149
void push_many(const std::vector< uint64_t > &items)
Adds multiple elements to the end of the sequence.
Definition dynamic_sequence64.hpp:219
static DynamicSequence64 build_from_data(const std::vector< uint8_t > &data, uint64_t &pos)
Builds a sequence from a vector of bytes.
Definition dynamic_sequence64.hpp:298
void decrement(uint64_t i, int64_t delta)
Decrements the value at a specified position by a given delta.
Definition dynamic_sequence64.hpp:198
uint64_t size() const
Returns the number of elements in the sequence.
Definition dynamic_sequence64.hpp:115
static void save(DynamicSequence64 &item, std::ofstream &os)
Saves the sequence to a file.
Definition dynamic_sequence64.hpp:287
void verify() const
Verifies the integrity of the sequence.
Definition dynamic_sequence64.hpp:76
Tree::ValueForwardIterator begin() const
Returns an iterator to the beginning of the sequence.
Definition dynamic_sequence64.hpp:31
static DynamicSequence64 build(const std::vector< uint64_t > &items)
Builds a new sequence from a vector of items.
Definition dynamic_sequence64.hpp:103
uint64_t operator[](uint64_t n) const
Returns the value at a specified position in the sequence.
Definition dynamic_sequence64.hpp:321
static DynamicSequence64 build_from_data(std::ifstream &ifs)
Builds a sequence from a file.
Definition dynamic_sequence64.hpp:310
void insert(uint64_t pos, uint64_t value)
Inserts a value at a specified position in the sequence.
Definition dynamic_sequence64.hpp:141
Tree & get_tree()
Returns a reference to the underlying tree.
Definition dynamic_sequence64.hpp:84
uint64_t at(uint64_t pos) const
Returns the value at a specified position in the sequence.
Definition dynamic_sequence64.hpp:167
std::string to_string() const
Converts the sequence to a string.
Definition dynamic_sequence64.hpp:329