23#include "pasta/bit_vector/bit_vector.hpp"
24#include "pasta/bit_vector/support/find_l2_flat_with.hpp"
25#include "pasta/bit_vector/support/l12_type.hpp"
30#include <pasta/utils/debug_asserts.hpp>
31#include <tlx/container/simple_vector.hpp>
47 static_cast<uint32_t
>(std::numeric_limits<int32_t>::max()) + 1;
84 template <OptimizedFor o, FindL2FlatWith f,
typename v>
91 VectorType::RawDataConstAccess
data_;
94 tlx::SimpleVector<BigL12Type, tlx::SimpleVectorMode::NoInitNoDestroy>
l12_;
109 data_(bv.data().data()),
119 [[nodiscard(
"rank0 computed but not used")]]
size_t
121 return index -
rank1(index);
129 [[nodiscard(
"rank1 computed but not used")]]
size_t
131 size_t offset = ((index / 512) * 8);
135 size_t result =
l12_[l1_pos].l1() +
l12_[l1_pos][l2_pos];
149 PASTA_ASSERT(index < 512,
150 "Trying to access bits that should be "
151 "covered in an L1-block");
152 for (
size_t i = 0; i < index / 64; ++i) {
153 result += std::popcount(
data_[offset++]);
155 if (index %= 64; index > 0) [[likely]] {
156 uint64_t
const remaining = (
data_[offset]) << (64 - index);
157 result += std::popcount(remaining);
166 [[nodiscard(
"space useage computed but not used")]]
virtual size_t
175 uint64_t
const* data =
data_;
178 uint64_t l1_entry = 0ULL;
179 std::array<uint16_t, 7> l2_entries = {0, 0, 0, 0, 0, 0, 0};
181 while (data + 64 < data_end) {
183 l2_entries[0] = popcount<8>(data);
185 l2_entries[0] = popcount_zeros<8>(data);
188 for (
size_t i = 1; i < 7; ++i) {
190 l2_entries[i] = l2_entries[i - 1] + popcount<8>(data);
192 l2_entries[i] = l2_entries[i - 1] + popcount_zeros<8>(data);
198 l1_entry += l2_entries.back() + popcount<8>(data);
200 l1_entry += l2_entries.back() + popcount_zeros<8>(data);
205 l2_entries = {0, 0, 0, 0, 0, 0, 0};
206 while (data + 8 < data_end) {
208 l2_entries[l2_pos++] = popcount<8>(data);
210 l2_entries[l2_pos++] = popcount_zeros<8>(data);
215 while (data < data_end) {
217 l2_entries[l2_pos] += popcount<1>(data++);
219 l2_entries[l2_pos] += popcount_zeros<1>(data++);
223 std::partial_sum(l2_entries.begin(), l2_entries.end(), l2_entries.begin());
Uncompressed, highly tuned, fixed size bit vector.
Definition bit_vector.hpp:178
Select support for BitVector that can be used as an alternative to RankSelect for bit vectors up to l...
Definition flat_rank_select.hpp:73
Rank support for BitVector that can be used as an alternative to Rank for bit vectors up to length 2^...
Definition flat_rank.hpp:82
virtual size_t space_usage() const
Estimate for the space usage.
Definition flat_rank.hpp:167
FlatRank()=default
Default constructor w/o parameter.
tlx::SimpleVector< BigL12Type, tlx::SimpleVectorMode::NoInitNoDestroy > l12_
Array containing the information about the L1- and L2-blocks.
Definition flat_rank.hpp:94
size_t rank1(size_t index) const
Computes rank of ones.
Definition flat_rank.hpp:130
size_t rank0(size_t index) const
Computes rank of zeros.
Definition flat_rank.hpp:120
FlatRank(VectorType &bv)
Constructor. Creates the auxiliary information for efficient rank queries.
Definition flat_rank.hpp:107
size_t l12_end_
Number of actual existing BigL12-blocks (important for scanning)
Definition flat_rank.hpp:96
size_t data_size_
Size of the bit vector the rank support is constructed for.
Definition flat_rank.hpp:89
VectorType::RawDataConstAccess data_
Pointer to the data of the bit vector.
Definition flat_rank.hpp:91
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).
Check that L12Type requires only 64 bits.
Definition l12_type.hpp:94
Static configuration for FlatRank and FlatRankSelect.
Definition flat_rank.hpp:40
static constexpr size_t L2_WORD_SIZE
Number of 64-bit words covered by an L2-block.
Definition flat_rank.hpp:50
static constexpr size_t L1_BIT_SIZE
Bits covered by an L1-block.
Definition flat_rank.hpp:44
static constexpr size_t L0_WORD_SIZE
Number of 64-bit words covered by an L0-block.
Definition flat_rank.hpp:54
static constexpr size_t L2_BIT_SIZE
Bits covered by an L2-block.
Definition flat_rank.hpp:42
static constexpr size_t SELECT_SAMPLE_RATE
Sample rate of positions for faster select queries.
Definition flat_rank.hpp:57
static constexpr size_t L0_BIT_SIZE
Bits covered by an L0-block.
Definition flat_rank.hpp:46
static constexpr size_t L1_WORD_SIZE
Number of 64-bit words covered by an L1-block.
Definition flat_rank.hpp:52