From 95b27798f1f0849454c328619c7745f842388ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20G=C3=BCndling?= Date: Thu, 11 Apr 2024 19:05:23 +0200 Subject: [PATCH] bitvec ctor with existing block vector: set size --- include/cista/containers/bitvec.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/cista/containers/bitvec.h b/include/cista/containers/bitvec.h index a8d0f65c..9406ff4d 100644 --- a/include/cista/containers/bitvec.h +++ b/include/cista/containers/bitvec.h @@ -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); @@ -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(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(to_idx(i)) / bits_per_block]; + auto const bit = to_idx(i) % bits_per_block; if (val) { block |= (block_t{1U} << bit); } else {