Bit vector
0.9
Fast and space efficient dynamic bit vector library.
|
1 #ifndef BV_BIT_VECTOR_HPP
2 #define BV_BIT_VECTOR_HPP
11 #include "query_support.hpp"
35 template <
class leaf,
class node,
class allocator, uint64_t leaf_size,
36 uint8_t branches,
class dtype>
128 template <dtype block_size = 2048>
131 static_assert(block_size * 3 <= leaf_size);
132 static_assert(block_size >= 2 * 64);
136 n_root_->generate_query_structure(qs);
149 template <dtype block_size = leaf_size / 3>
151 static_assert(block_size * 3 <= leaf_size);
174 void insert(uint64_t index,
bool value) {
176 if (index >
size()) {
177 std::cerr <<
"Invalid insertion to index " << index <<
" for "
178 <<
size() <<
" element bit vector." << std::endl;
179 assert(index <=
size());
186 leaf_size / (2 * WORD_BITS));
248 [[unlikely]] (void(0));
297 bool at(uint64_t index)
const {
315 uint64_t
rank(uint64_t index)
const {
349 void set(uint64_t index,
bool value) {
396 uint64_t allocs =
allocator_->live_allocations();
416 void print(
bool internal_only)
const {
419 std::cout << std::endl;
void set(uint64_t index, bool value)
Sets the bit at "index" to "value".
Definition: bit_vector.hpp:349
int set(const uint64_t i, const bool x)
Set the ith bit to x.
Definition: leaf.hpp:274
void generate_query_structure(query_support< dtype, leaf, block_size > *qs) const
Populate a given query support stucture using this
Definition: bit_vector.hpp:129
int set(dtype index, bool v)
Set the value of the logical indexth element to v.
Definition: node.hpp:174
void deallocate(allocator *alloc)
Recursively deallocates all children.
Definition: node.hpp:258
uint64_t validate() const
Ensure that the leaf is in a valid state.
Definition: leaf.hpp:1069
uint64_t sum() const
Number of 1-bits in the data structure.
Definition: bit_vector.hpp:263
query_support< dtype, leaf, block_size > * generate_query_structure() const
Create and Populate a query support structure using this
Definition: bit_vector.hpp:150
uint64_t bit_size() const
Total size of data structure allocations in bits.
Definition: bit_vector.hpp:374
Container class for dynamic b-tree bit vector stuctures.
Definition: bit_vector.hpp:37
uint64_t size() const
Number of elements stored in the data structure.
Definition: bit_vector.hpp:275
void append(leaf_type *leaf)
Add leaf reference to the support structure.
Definition: query_support.hpp:66
Support structure for bv::bit_vector to enable fast queries.
Definition: query_support.hpp:49
void transfer_append(leaf *other, uint64_t elems)
Move "elems" elements from the start of "other" to the end of "this".
Definition: leaf.hpp:738
bool owned_allocator_
True if deallocating the allocator is the responsibilty of the data structure.
Definition: bit_vector.hpp:41
void flush()
Recursively flushes all buffers in the data structure.
Definition: bit_vector.hpp:361
bool at(const uint32_t i) const
Get the value of the ith element in the leaf.
Definition: leaf.hpp:101
uint32_t p_sum() const
Getter for p_sum_.
Definition: leaf.hpp:122
bool root_is_leaf_
Value indicating whether the root is in n_root_ or l_root_.
Definition: bit_vector.hpp:39
dtype rank(dtype index) const
Counts number of one bits up to the indexth logical element.
Definition: node.hpp:202
uint64_t rank(uint64_t index) const
Number of 1-bits up to position index.
Definition: bit_vector.hpp:315
~bit_vector()
Deconstructor that deallocates the entire data structure.
Definition: bit_vector.hpp:107
dtype p_sum() const
Logical number of 1-bits stored in the subtree.
Definition: node.hpp:323
void print(bool internal_only) const
Output data stored in the leaf as json.
Definition: leaf.hpp:1096
bit_vector(allocator *alloc)
Bit vector constructor with existing allocator.
Definition: bit_vector.hpp:80
simple_bv< 8, 16384, 64 > bv
Default dynamic bit vector type.
Definition: bv.hpp:94
void insert(dtype index, bool value, allocator *alloc)
Insert "value" at "index".
Definition: node.hpp:369
void append_child(child *new_child)
Add child to the subtree.
Definition: node.hpp:337
uint32_t capacity() const
Size of the leaf-associated data storage in 64-bit words.
Definition: leaf.hpp:637
void split_root()
Increases the height of the tree by one level.
Definition: bit_vector.hpp:59
void finalize()
Prepare the structure for querying.
Definition: query_support.hpp:88
Simple flat dynamic bit vector for use as a leaf for a dynamic b-tree bit vector.
Definition: leaf.hpp:47
void * child(uint8_t i)
Get ith child of the node.
Definition: node.hpp:353
void print(bool internal_only) const
Outputs this subtree as json.
Definition: node.hpp:606
void has_leaves(bool leaves)
Set whether the children of the node are leaves or internal nodes.
Definition: node.hpp:131
void insert(const uint64_t i, const bool x)
Insert x into position i.
Definition: leaf.hpp:140
bool remove(const uint64_t i)
Remove the ith bit from the leaf.
Definition: leaf.hpp:207
bool remove(uint64_t index)
Remove element at "index".
Definition: bit_vector.hpp:233
uint32_t size() const
Getter for size_.
Definition: leaf.hpp:124
bit_vector()
Default constructor that creates an owned allocator.
Definition: bit_vector.hpp:92
dtype size() const
Logical number of elements stored in the subtree.
Definition: node.hpp:314
leaf * l_root_
Root if a single leaf is sufficient.
Definition: bit_vector.hpp:46
bool remove(dtype index, allocator *alloc)
Remove the indexth element.
Definition: node.hpp:389
allocator * allocator_
Pointer to allocator used for allocating internal nodes and leaves.
Definition: bit_vector.hpp:47
dtype select(dtype count) const
Calculates the index of the counttu 1-bit.
Definition: node.hpp:230
bool need_realloc() const
Determine if reallocation / splitting is required prior to additional insertion of new elements.
Definition: leaf.hpp:628
bool at(uint64_t index) const
Retrieves the value of the indexth element in the data structure.
Definition: bit_vector.hpp:297
uint64_t bits_size() const
Size of the leaf and associated data in bits.
Definition: leaf.hpp:617
uint64_t validate() const
Check that the subtree structure is internally consistent.
Definition: node.hpp:563
Internal node for use with bit vector b-tree structures.
Definition: node.hpp:65
bool at(dtype index) const
Access the value of the indexth element of the logical structure.
Definition: node.hpp:150
void commit()
Commit and clear the Insert/Remove buffer for the leaf.
Definition: leaf.hpp:955
uint64_t select(uint64_t count) const
Index of the countth 1-bit in the data structure.
Definition: bit_vector.hpp:333
uint32_t rank(const uint64_t n) const
Number of 1-bits up to position n.
Definition: leaf.hpp:323
node * n_root_
Root of the b-tree if a multi-level structure is required.
Definition: bit_vector.hpp:44
uint64_t bits_size() const
Size of the subtree in "allocated" bits.
Definition: node.hpp:511
void insert(uint64_t index, bool value)
Insert "value" into position "index".
Definition: bit_vector.hpp:174
void validate() const
Asserts that the data structure is internally consistent.
Definition: bit_vector.hpp:394
void transfer_prepend(node *other, uint8_t elems)
Moves the last "elems" elements from "other" to the start of "this".
Definition: node.hpp:466
uint32_t select(const uint32_t x) const
Index of the xth 1-bit in the data structure.
Definition: leaf.hpp:444
uint8_t child_count() const
Get the number of children of this node.
Definition: node.hpp:280
void print(bool internal_only) const
Output data structure to standard out as json.
Definition: bit_vector.hpp:416