23#include "pasta/bit_vector/bit_vector.hpp"
24#include "pasta/bit_vector/support/find_l2_wide_with.hpp"
25#include "pasta/bit_vector/support/l12_type.hpp"
28#include "pasta/utils/container/aligned_vector.hpp"
30#include <tlx/container/simple_vector.hpp>
78 template <OptimizedFor o, FindL2W
ideWith f,
typename v>
84 VectorType::RawDataConstAccess data_;
87 tlx::SimpleVector<uint64_t, tlx::SimpleVectorMode::NoInitNoDestroy> l1_;
89 tlx::SimpleVector<uint16_t, tlx::SimpleVectorMode::NoInitNoDestroy> l2_;
101 : data_size_(bv.data().size()),
102 data_(bv.data().data()),
113 [[nodiscard(
"rank0 computed but not used")]]
size_t
115 return index -
rank1(index);
123 [[nodiscard(
"rank1 computed but not used")]]
size_t
127 size_t result = l1_[l1_pos] + l2_[l2_pos];
135 for (
size_t i = 0; i < full_words; ++i) {
136 result += std::popcount(data_[offset++]);
139 if (index %= 64; index > 0) [[likely]] {
140 uint64_t
const remaining = data_[offset] << (64 - index);
141 result += std::popcount(remaining);
150 [[nodiscard(
"space useage computed but not used")]]
virtual size_t
152 return (l1_.size() *
sizeof(uint64_t)) + (l2_.size() *
sizeof(uint16_t)) +
160 uint64_t
const* data = data_;
161 uint64_t
const*
const data_end = data_ + data_size_;
168 while (data + 8 < data_end) {
169 l2_[l2_pos++] = l2_entry;
171 l2_entry += popcount<8>(data);
173 l2_entry += popcount_zeros<8>(data);
176 if (l2_pos % 128 == 0 && l2_pos > 0) [[unlikely]] {
178 l1_[l1_pos] = l1_[l1_pos - 1] + l2_entry;
182 l2_[l2_pos++] = l2_entry;
Uncompressed, highly tuned, fixed size bit vector.
Definition bit_vector.hpp:178
Select support for BitVector.
Definition wide_rank_select.hpp:62
Rank support for BitVector that can be used as an alternative to Rank for bit vectors up to length 2^...
Definition wide_rank.hpp:76
size_t rank1(size_t index) const
Computes rank of ones.
Definition wide_rank.hpp:124
WideRank(VectorType &bv)
Constructor. Creates the auxiliary information for efficient rank queries.
Definition wide_rank.hpp:100
virtual size_t space_usage() const
Estimate for the space usage.
Definition wide_rank.hpp:151
WideRank()=default
Default constructor w/o parameter.
size_t rank0(size_t index) const
Computes rank of zeros.
Definition wide_rank.hpp:114
OptimizedFor
Enum used to specify which queries the rank (and select) data structures should be optimized for.
Definition optimized_for.hpp:40
constexpr bool optimize_one_or_dont_care(OptimizedFor const optimized_for)
Helper function indicating if queries should be optimized for one queries or the caller does not care...
Definition optimized_for.hpp:59
@ DONT_CARE
It does not matter (both types are called equally often).
Static configuration for WideRank and WideRankSelect.
Definition wide_rank.hpp:39
static constexpr size_t L1_WORD_SIZE
Number of 64-bit words covered by an L1-block.
Definition wide_rank.hpp:48
static constexpr size_t L2_WORD_SIZE
Number of 64-bit words covered by an L2-block.
Definition wide_rank.hpp:46
static constexpr size_t L1_BIT_SIZE
Bits covered by an L1-block.
Definition wide_rank.hpp:43
static constexpr size_t SELECT_SAMPLE_RATE
Sample rate of positions for faster select queries.
Definition wide_rank.hpp:51
static constexpr size_t L2_BIT_SIZE
Bits covered by an L2-block.
Definition wide_rank.hpp:41