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_);
296 size_((bit_size_ >> 6) + 1),
298 raw_data_(data_.data()) {}
309 uint64_t
const fill_value = init_value ? ~(0ULL) : 0ULL;
310 std::fill_n(raw_data_, size_, fill_value);
337 size_ = (bit_size_ >> 6) + 1;
339 raw_data_ = data_.data();
348 void resize(
size_t const size,
bool const init_value)
noexcept {
349 size_t const old_bit_size = bit_size_;
351 size_ = (bit_size_ >> 6) + 1;
353 raw_data_ = data_.data();
355 if (old_bit_size < bit_size_) {
356 size_t max_bitwise = std::min(bit_size_, ((old_bit_size + 63) / 64) * 64);
357 for (
size_t i = old_bit_size; i < max_bitwise; ++i) {
360 size_t const old_size = (old_bit_size + 63) / 64;
361 uint64_t
const fill_value = init_value ? ~(0ULL) : 0ULL;
362 std::fill_n(raw_data_ + old_size, size_ - old_size, fill_value);
382 return Iterator(raw_data_, bit_size_);
392 std::span<uint64_t>
data() noexcept {
393 return std::span{raw_data_, size_};
403 std::span<uint64_t>
data() const noexcept {
404 return std::span{raw_data_, size_};
416 uint64_t
data(
size_t const index)
const noexcept {
417 return raw_data_[index];
424 [[nodiscard(
"space usage computed but not used")]]
size_t
426 return (data_.size() *
sizeof(
RawDataType)) +
sizeof(*this);
439 for (
size_t i = 0; i < bv.bit_size_; ++i) {
440 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:370
BitAccess operator[](size_t const index) const noexcept
Access operator to read to a bit of the bit vector.
Definition bit_vector.hpp:327
BitVector & operator=(BitVector const &)=delete
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:438
std::span< uint64_t > data() const noexcept
Direct access to the raw data of the bit vector.
Definition bit_vector.hpp:403
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:433
BitVector(BitVector &&)=default
Default move constructor.
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:307
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:416
BitVector(BitVector const &)=default
Default copy constructor.
Iterator end() noexcept
Get iterator representing the end of the BitVector.
Definition bit_vector.hpp:381
void resize(size_t const size) noexcept
Resize the bit vector to contain size bits.
Definition bit_vector.hpp:335
std::span< uint64_t > data() noexcept
Direct access to the raw data of the bit vector.
Definition bit_vector.hpp:392
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:348
BitVector & operator=(BitVector &&)=default
Default move assignment.
size_t space_usage() const
Estimate for the space usage.
Definition bit_vector.hpp:425
BitVector(size_t const size) noexcept
Constructor. Creates a bit vector that holds a specific, fixed number of bits.
Definition bit_vector.hpp:294
BitAccess operator[](size_t const index) noexcept
Access operator to read/write to a bit of the bit vector.
Definition bit_vector.hpp:318
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