23#include "pasta/bit_vector/support/find_l2_flat_with.hpp"
24#include "pasta/bit_vector/support/find_l2_wide_with.hpp"
33#include <tlx/container/simple_vector.hpp>
50 uint64_t*
const data_;
76 BitAccess(uint64_t*
const data,
size_t const position) noexcept
78 position_(position) {}
86 operator bool() const noexcept {
87 uint8_t
const offset = uint64_t(position_) & uint64_t(0b111111);
88 return (data_[position_ >> 6] >> offset) & 1ULL;
99 uint64_t
const mask = 1ULL << (uint64_t(position_) & uint64_t(0b111111));
100 data_[position_ >> 6] = (data_[position_ >> 6] & ~mask) | (-value & mask);
114 return position_ - other.position_;
129 return a.position_ == b.position_ && a.data_ == b.data_;
144 return a.position_ != b.position_ || a.data_ != b.data_;
191 size_t bit_size_ = 0;
195 tlx::SimpleVector<RawDataType, tlx::SimpleVectorMode::NoInitNoDestroy> data_;
222 : bit_access_(
data, position) {}
242 ++bit_access_.position_;
255 return a.bit_access_ == b.bit_access_;
260 return a.bit_access_ != b.bit_access_;
266 return a.bit_access_.distance(b.bit_access_);
289 size_((bit_size_ >> 6) + 1),
291 raw_data_(data_.data()) {}
302 uint64_t
const fill_value = init_value ? ~(0ULL) : 0ULL;
303 std::fill_n(raw_data_, size_, fill_value);
330 size_ = (bit_size_ >> 6) + 1;
332 raw_data_ = data_.data();
341 void resize(
size_t const size,
bool const init_value)
noexcept {
342 size_t const old_bit_size = bit_size_;
344 size_ = (bit_size_ >> 6) + 1;
346 raw_data_ = data_.data();
348 if (old_bit_size < bit_size_) {
349 size_t max_bitwise = std::min(bit_size_, ((old_bit_size + 63) / 64) * 64);
350 for (
size_t i = old_bit_size; i < max_bitwise; ++i) {
353 size_t const old_size = (old_bit_size + 63) / 64;
354 uint64_t
const fill_value = init_value ? ~(0ULL) : 0ULL;
355 std::fill_n(raw_data_ + old_size, size_ - old_size, fill_value);
375 return Iterator(raw_data_, bit_size_);
385 std::span<uint64_t>
data() noexcept {
386 return std::span{raw_data_, size_};
396 std::span<uint64_t>
data() const noexcept {
397 return std::span{raw_data_, size_};
409 uint64_t
data(
size_t const index)
const noexcept {
410 return raw_data_[index];
417 [[nodiscard(
"space usage computed but not used")]]
size_t
419 return (data_.size() *
sizeof(
RawDataType)) +
sizeof(*this);
432 for (
size_t i = 0; i < bv.bit_size_; ++i) {
433 os << (bv[i] ?
"1" :
"0");
Utility class used for the access operator of the BitVector.
Definition bit_vector.hpp:45
BitAccess(BitAccess &&)=delete
Avoiding implicit generation of the move constructor.
int64_t distance(BitAccess const &other) const noexcept
Computes the distance to another BitAccess instance.
Definition bit_vector.hpp:113
BitAccess & operator=(BitAccess const &)=delete
Avoiding implicit copy assignment.
BitAccess & operator=(bool const value) noexcept
Assignment operator to set a bit within the bit vector.
Definition bit_vector.hpp:96
BitAccess()=delete
Deleted constructor.
BitAccess & operator=(BitAccess &&)=delete
Avoiding implicit move assignment.
friend bool operator==(BitAccess const &a, BitAccess const &b) noexcept
Comparison of two BitAccess instances for equality.
Definition bit_vector.hpp:128
BitAccess(uint64_t *const data, size_t const position) noexcept
Constructor setting 64-bit word and position of the bit in the word.
Definition bit_vector.hpp:76
friend bool operator!=(BitAccess const &a, BitAccess const &b) noexcept
Comparison of two BitAccess instances for inequality.
Definition bit_vector.hpp:143
Uncompressed, highly tuned, fixed size bit vector.
Definition bit_vector.hpp:178
Iterator begin() noexcept
Get iterator representing the first element of the BitVector.
Definition bit_vector.hpp:363
BitAccess operator[](size_t const index) const noexcept
Access operator to read to a bit of the bit vector.
Definition bit_vector.hpp:320
BitVector & operator=(BitVector const &)=delete
Deleted copy assignment.
uint64_t RawDataType
Type that is used to store the raw data of the bit vector.
Definition bit_vector.hpp:181
BitVector()=default
Default empty constructor.
RawDataType const * RawDataConstAccess
Definition bit_vector.hpp:187
friend std::ostream & operator<<(std::ostream &os, BitVector const &bv)
formatted output of the BitVector
Definition bit_vector.hpp:431
std::span< uint64_t > data() const noexcept
Direct access to the raw data of the bit vector.
Definition bit_vector.hpp:396
RawDataType * RawDataPointer
Definition bit_vector.hpp:184
size_t size() const noexcept
Get the size of the bit vector in bits.
Definition bit_vector.hpp:426
BitVector(size_t const size, bool const init_value) noexcept
Constructor. Creates a bit vector that holds a specific, fixed number of bits set to a default value.
Definition bit_vector.hpp:300
uint64_t data(size_t const index) const noexcept
Direct access to one 64-bit element of the raw data of the bit vector.
Definition bit_vector.hpp:409
Iterator end() noexcept
Get iterator representing the end of the BitVector.
Definition bit_vector.hpp:374
BitVector(BitVector const &)=delete
Deleted copy constructor.
void resize(size_t const size) noexcept
Resize the bit vector to contain size bits.
Definition bit_vector.hpp:328
std::span< uint64_t > data() noexcept
Direct access to the raw data of the bit vector.
Definition bit_vector.hpp:385
void resize(size_t const size, bool const init_value) noexcept
Resize the bit vector to contain size bits and fill new bits with default value.
Definition bit_vector.hpp:341
size_t space_usage() const
Estimate for the space usage.
Definition bit_vector.hpp:418
BitVector(size_t const size) noexcept
Constructor. Creates a bit vector that holds a specific, fixed number of bits.
Definition bit_vector.hpp:287
BitAccess operator[](size_t const index) noexcept
Access operator to read/write to a bit of the bit vector.
Definition bit_vector.hpp:311
Custom iterator for BitVector.
Definition bit_vector.hpp:203
friend bool operator==(Iterator const &a, Iterator const &b) noexcept
Iterator comparison equality.
Definition bit_vector.hpp:254
Iterator operator++(int32_t) noexcept
Postfix increment.
Definition bit_vector.hpp:247
Iterator & operator++() noexcept
Prefix increment.
Definition bit_vector.hpp:241
std::forward_iterator_tag iterator_category
Iterator category.
Definition bit_vector.hpp:205
Iterator(uint64_t *const data, size_t const position) noexcept
Constructor. Creates Iterator pointing at a bit and holds pointer to data.
Definition bit_vector.hpp:221
friend bool operator!=(Iterator const &a, Iterator const &b) noexcept
Iterator comparison inequality.
Definition bit_vector.hpp:259
pointer operator->() noexcept
Iterator is dereferenceable. Obtain value it is pointing at.
Definition bit_vector.hpp:236
friend differece_type operator-(Iterator const &a, Iterator const &b) noexcept
Iterator distance computation.
Definition bit_vector.hpp:264
std::ptrdiff_t differece_type
Difference type.
Definition bit_vector.hpp:207
reference operator*() noexcept
Iterator is dereferenceable. Obtain value it is pointing at.
Definition bit_vector.hpp:228