3#ifndef PIXIE_SUCCINCT_BITVEC_SUPPORT
4#error "SuccinctFastRankSelectSupport requires PIXIE_THIRD_PARTY_BACKENDS"
34 static constexpr std::uint64_t
kMaxBits = std::uint64_t{1} << 32;
44 std::span<const std::uint64_t> source_words,
46 : bits_(checked_size(source_words, num_bits)),
47 support_(copy_source(bits_, source_words)) {}
60 int bit_impl(std::size_t position)
const {
return bits_.get(position); }
65 return support_.get_total_ones();
67 return end == 0 ? 0 : support_.rank1(end - 1);
73 if (occurrence == 0) {
76 if (occurrence > support_.get_total_ones()) {
79 return static_cast<std::uint64_t
>(support_.select1(occurrence - 1));
88 return occurrence == 0 ? 0 :
size();
93 return bits_.words.capacity() *
sizeof(std::uint64_t);
101 return sizeof(*this) + support_.overhead_bytes();
110 static std::size_t checked_size(std::span<const std::uint64_t> source,
111 std::size_t num_bits) {
112 if (source.size() <= std::numeric_limits<std::size_t>::max() / 64) {
113 num_bits = std::min(num_bits, source.size() * 64);
116 throw std::length_error(
117 "FastBitVec select samples support at most 2^32 bits");
122 static const succinct::RawBits& copy_source(
123 succinct::RawBits& bits,
124 std::span<const std::uint64_t> source) {
125 const std::size_t word_count = std::min(bits.num_words, source.size());
126 std::copy_n(source.begin(), word_count, bits.words.begin());
127 if (bits.len % 64 != 0) {
128 bits.words.back() &= (std::uint64_t{1} << (bits.len % 64)) - 1;
133 succinct::RawBits bits_;
134 succinct::FastBitVec support_;
CRTP facade for immutable rank/select queries and bit access.
Definition rank_select.h:32
std::size_t size() const
Definition rank_select.h:39
Optional rank/select implementation over succinct-bitvec-cpp's FastBitVec.
Definition succinct_bitvec.h:31
std::uint64_t select_impl(std::size_t occurrence) const
Return a one-based one's position, zero for zero, size() if absent.
Definition succinct_bitvec.h:72
std::size_t memory_usage_bytes_impl() const
Return reported index bytes plus the allocated source copy.
Definition succinct_bitvec.h:105
std::size_t source_copy_bytes() const
Return allocated bytes in the normalized source copy.
Definition succinct_bitvec.h:92
static constexpr std::uint64_t kMaxBits
Largest supported source; its last bit fits a uint32_t sample.
Definition succinct_bitvec.h:34
int bit_impl(std::size_t position) const
Return a source bit; position must be below size().
Definition succinct_bitvec.h:60
std::size_t index_logical_bytes() const
Return object plus upstream-reported logical index bytes.
Definition succinct_bitvec.h:100
bool supports_select0_impl() const
The pinned upstream implementation has no zero-select API.
Definition succinct_bitvec.h:85
std::uint64_t select0_impl(std::size_t occurrence) const
Return zero for occurrence zero, otherwise size(): disabled.
Definition succinct_bitvec.h:87
std::uint64_t rank_impl(std::size_t end) const
Count ones in [0, end), clamping end to size().
Definition succinct_bitvec.h:63
std::size_t size_impl() const
Return the logical source length.
Definition succinct_bitvec.h:57
bool supports_select1_impl() const
FastBitVec always builds one-select metadata.
Definition succinct_bitvec.h:83
SuccinctFastRankSelectSupport(std::span< const std::uint64_t > source_words, std::size_t num_bits)
Build FastBitVec over an owned least-significant-bit-first source.
Definition succinct_bitvec.h:43
Common interface for rank/select support over packed bit sequences.