Skip to content

Commit

Permalink
bitvec ctor with existing block vector: set size
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Apr 11, 2024
1 parent 251a73b commit 95b2779
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions include/cista/containers/bitvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ struct basic_bitvec {

constexpr basic_bitvec() noexcept {}
constexpr basic_bitvec(std::string_view s) noexcept { set(s); }
constexpr basic_bitvec(Vec&& v) noexcept : blocks_{std::move(v)} {}
constexpr basic_bitvec(Vec&& v) noexcept
: size_{v.size() * bits_per_block}, // inaccurate for loading mmap vector
blocks_{std::move(v)} {}
static constexpr basic_bitvec max(std::size_t const size) {
basic_bitvec ret;
ret.resize(size);
Expand Down Expand Up @@ -66,9 +68,9 @@ struct basic_bitvec {

constexpr void set(Key const i, bool const val = true) noexcept {
assert(i < size_);
assert((i / bits_per_block) < blocks_.size());
auto& block = blocks_[static_cast<size_type>(i) / bits_per_block];
auto const bit = i % bits_per_block;
assert((to_idx(i) / bits_per_block) < blocks_.size());
auto& block = blocks_[static_cast<size_type>(to_idx(i)) / bits_per_block];
auto const bit = to_idx(i) % bits_per_block;
if (val) {
block |= (block_t{1U} << bit);
} else {
Expand Down

0 comments on commit 95b2779

Please sign in to comment.