4#error "SdslRankSelectSupport requires PIXIE_THIRD_PARTY_BACKENDS"
14#pragma push_macro("ALIGNMENT")
15#include <sdsl/int_vector.hpp>
16#include <sdsl/rank_support_v.hpp>
17#include <sdsl/select_support_mcl.hpp>
18#pragma pop_macro("ALIGNMENT")
40 : bits_(copy_source(source_words, num_bits)),
44 one_count_(bits_.
empty() ? 0 : rank_(bits_.
size())) {}
52 std::size_t
size_impl()
const {
return bits_.size(); }
55 int bit_impl(std::size_t position)
const {
return bits_[position]; }
59 return end >=
size() ? one_count_ : rank_(end);
64 return occurrence == 0 ? 0
65 : occurrence > one_count_ ?
size()
66 : select1_(occurrence);
71 return occurrence == 0 ? 0
72 : occurrence >
size() - one_count_ ?
size()
73 : select0_(occurrence);
92 return sizeof(*this) + sdsl::size_in_bytes(rank_) +
93 sdsl::size_in_bytes(select1_) + sdsl::size_in_bytes(select0_);
102 static sdsl::bit_vector copy_source(
103 std::span<const std::uint64_t> source_words,
104 std::size_t num_bits) {
105 if (source_words.size() <= std::numeric_limits<std::size_t>::max() / 64) {
106 num_bits = std::min(num_bits, source_words.size() * 64);
108 sdsl::bit_vector result(num_bits, 0);
109 const std::size_t words = num_bits / 64 + (num_bits % 64 != 0);
110 std::copy_n(source_words.begin(), words, result.data());
111 if (num_bits % 64 != 0) {
112 result.data()[words - 1] &= (std::uint64_t{1} << (num_bits % 64)) - 1;
117 sdsl::bit_vector bits_;
118 sdsl::rank_support_v<> rank_;
119 sdsl::select_support_mcl<1> select1_;
120 sdsl::select_support_mcl<0> select0_;
121 std::size_t one_count_;
CRTP facade for immutable rank/select queries and bit access.
Definition rank_select.h:32
bool empty() const
Definition rank_select.h:45
std::size_t size() const
Definition rank_select.h:39
Optional SDSL rank-v index with MCL select in both directions.
Definition sdsl.h:30
std::size_t size_impl() const
Return the logical bit count.
Definition sdsl.h:52
bool supports_select1_impl() const
SDSL constructs one-select support unconditionally.
Definition sdsl.h:77
bool supports_select0_impl() const
SDSL constructs zero-select support unconditionally.
Definition sdsl.h:80
SdslRankSelectSupport(std::span< const std::uint64_t > source_words, std::size_t num_bits)
Copy packed source words and build rank1, select1 and select0.
Definition sdsl.h:38
std::uint64_t select_impl(std::size_t occurrence) const
Locate a one-based one occurrence, or size() if absent.
Definition sdsl.h:63
int bit_impl(std::size_t position) const
Read a zero-based bit; position must be below size().
Definition sdsl.h:55
std::uint64_t rank_impl(std::size_t end) const
Count ones in [0, end), clamping end to size().
Definition sdsl.h:58
std::size_t memory_usage_bytes_impl() const
Return the reported index footprint and owned source bytes.
Definition sdsl.h:97
std::size_t index_logical_bytes() const
Return object bytes plus SDSL's serialized logical directory sizes.
Definition sdsl.h:91
std::size_t source_copy_bytes() const
Return allocated bytes in the owned source buffer.
Definition sdsl.h:83
std::uint64_t select0_impl(std::size_t occurrence) const
Locate a one-based zero occurrence, or size() if absent.
Definition sdsl.h:70
Common interface for rank/select support over packed bit sequences.