Pixie
Loading...
Searching...
No Matches
pixie::RankSelectSupport< MetadataStorage > Class Template Reference

Rank/select support over an external packed bit sequence. More...

#include <support.h>

Inheritance diagram for pixie::RankSelectSupport< MetadataStorage >:
pixie::RankSelectBase< RankSelectSupport< AlignedStorage > >

Public Types

enum class  SelectSupport : uint8_t { kNone = 0 , kSelect1 = 1 , kSelect0 = 2 , kBoth = 3 }
 Select directions to index during construction.
 

Public Member Functions

 RankSelectSupport (const RankSelectSupport &)=default
 
 RankSelectSupport (RankSelectSupport &&) noexcept=default
 
RankSelectSupportoperator= (const RankSelectSupport &)=default
 
RankSelectSupportoperator= (RankSelectSupport &&) noexcept=default
 
 RankSelectSupport (ReadOnlyStorageView source_storage, size_t num_bits, SelectSupport select_support=SelectSupport::kBoth, std::optional< size_t > one_count=std::nullopt)
 Construct support over a read-only storage view.
 
 RankSelectSupport (std::span< const uint64_t > source_words, size_t num_bits, SelectSupport select_support=SelectSupport::kBoth, std::optional< size_t > one_count=std::nullopt)
 Construct support over caller-owned packed 64-bit words.
 
template<StorageImplementation SourceStorage>
 RankSelectSupport (const SourceStorage &source_storage, size_t num_bits, SelectSupport select_support=SelectSupport::kBoth, std::optional< size_t > one_count=std::nullopt)
 Construct support over a Pixie storage implementation.
 
size_t size_impl () const
 Returns the number of valid bits.
 
bool supports_select1_impl () const
 Whether this index stores samples for select1 queries.
 
bool supports_select0_impl () const
 Whether this index stores samples for select0 queries.
 
size_t memory_usage_bytes_impl () const
 Return owned auxiliary memory usage in bytes.
 
int bit_impl (size_t pos) const
 Returns the bit at the given position.
 
uint64_t rank_impl (size_t pos) const
 Rank of 1s up to position pos (exclusive).
 
uint64_t select_impl (size_t rank) const
 Rank of 0s up to position pos (exclusive).
 
uint64_t select0_impl (size_t rank0) const
 Select the position of the rank0-th 0-bit (1-indexed).
 
void serialize (pixie::OutputBitStream &bs) const
 
- Public Member Functions inherited from pixie::RankSelectBase< RankSelectSupport< AlignedStorage > >
std::size_t size () const
 Return the number of valid bits.
 
bool empty () const
 Check whether the bit vector is empty.
 
int operator[] (std::size_t position) const
 Read a bit by zero-based position.
 
std::uint64_t rank (std::size_t end_position) const
 Count one bits in the prefix [0, end_position).
 
std::uint64_t rank0 (std::size_t end_position) const
 Count zero bits in the prefix [0, end_position).
 
std::uint64_t select (std::size_t rank) const
 Return the position of the rank-th one bit.
 
std::uint64_t select0 (std::size_t rank) const
 Return the position of the rank-th zero bit.
 
bool supports_select1 () const
 Check whether select queries for one bits are enabled.
 
bool supports_select0 () const
 Check whether select queries for zero bits are enabled.
 
std::size_t memory_usage_bytes () const
 Return owned index memory usage when provided by the implementation.
 
std::string to_string () const
 Convert the logical bits to a binary string.
 

Static Public Member Functions

static RankSelectSupport deserialize (std::span< const uint64_t > source_bits, std::span< const std::byte > &data)
 

Detailed Description

template<StorageImplementation MetadataStorage = AlignedStorage>
class pixie::RankSelectSupport< MetadataStorage >

Rank/select support over an external packed bit sequence.

This object does not own its source bits. It owns rank/select metadata through MetadataStorage and keeps a read-only storage view plus a validated 64-bit-word view of the caller-owned source.

Structure overview:

  • Super blocks of 2^16 bits with 64-bit ranks (0.098% overhead).
  • Basic blocks of 512 bits with 16-bit ranks (3.125% overhead).
  • Optional 64-bit select samples every 2^14 occurrences. One enabled direction uses at most 0.391% overhead; when both directions are enabled, their combined asymptotic overhead is also 0.391%.

The rank metadata plus both select directions therefore use 3.613% asymptotic metadata overhead. These ratios exclude the object itself, sentinel entries, and 64-byte allocation rounding, which are included by memory_usage_bytes_impl().

Rank: 2 table lookups plus SIMD popcount in the 512-bit block.

Select:

  • Start from a sampled super block.
  • SIMD linear scan to find the super block.
  • SIMD linear scan to find the basic block.

This variant does not interleave data and index, favoring simpler scans. Rank metadata and enabled select samples are built in one scan over the source words.

Constructor & Destructor Documentation

◆ RankSelectSupport() [1/3]

template<StorageImplementation MetadataStorage = AlignedStorage>
pixie::RankSelectSupport< MetadataStorage >::RankSelectSupport ( ReadOnlyStorageView source_storage,
size_t num_bits,
SelectSupport select_support = SelectSupport::kBoth,
std::optional< size_t > one_count = std::nullopt )
inlineexplicit

Construct support over a read-only storage view.

Parameters
source_storagePacked source bytes, not owned.
num_bitsNumber of valid source bits.
select_supportWhich select sample tables to build. Rank and rank0 remain available in all modes.
one_countOptional exact number of 1-bits. When supplied, construction can allocate select sample storage exactly.

◆ RankSelectSupport() [2/3]

template<StorageImplementation MetadataStorage = AlignedStorage>
pixie::RankSelectSupport< MetadataStorage >::RankSelectSupport ( std::span< const uint64_t > source_words,
size_t num_bits,
SelectSupport select_support = SelectSupport::kBoth,
std::optional< size_t > one_count = std::nullopt )
inlineexplicit

Construct support over caller-owned packed 64-bit words.

Parameters
source_wordsPacked source words, not owned.
num_bitsNumber of valid source bits.
select_supportSelect sample tables to build.
one_countOptional exact number of one bits.

◆ RankSelectSupport() [3/3]

template<StorageImplementation MetadataStorage = AlignedStorage>
template<StorageImplementation SourceStorage>
pixie::RankSelectSupport< MetadataStorage >::RankSelectSupport ( const SourceStorage & source_storage,
size_t num_bits,
SelectSupport select_support = SelectSupport::kBoth,
std::optional< size_t > one_count = std::nullopt )
inlineexplicit

Construct support over a Pixie storage implementation.

The support retains a non-owning view. The source storage must remain alive and must not be resized while this object is used.

Parameters
source_storagePacked source storage, not owned.
num_bitsNumber of valid source bits.
select_supportSelect sample tables to build.
one_countOptional exact number of one bits.

Member Function Documentation

◆ bit_impl()

template<StorageImplementation MetadataStorage = AlignedStorage>
int pixie::RankSelectSupport< MetadataStorage >::bit_impl ( size_t pos) const
inline

Returns the bit at the given position.

Parameters
posBit index in [0, size()).

◆ memory_usage_bytes_impl()

template<StorageImplementation MetadataStorage = AlignedStorage>
size_t pixie::RankSelectSupport< MetadataStorage >::memory_usage_bytes_impl ( ) const
inline

Return owned auxiliary memory usage in bytes.

Counts this rank/select object and its owned aligned metadata buffers. The external source bit words are not owned and are excluded.

◆ rank_impl()

template<StorageImplementation MetadataStorage = AlignedStorage>
uint64_t pixie::RankSelectSupport< MetadataStorage >::rank_impl ( size_t pos) const
inline

Rank of 1s up to position pos (exclusive).

Parameters
posBit index in [0, size()].
Returns
Number of 1s in [0, pos).

◆ select0_impl()

template<StorageImplementation MetadataStorage = AlignedStorage>
uint64_t pixie::RankSelectSupport< MetadataStorage >::select0_impl ( size_t rank0) const
inline

Select the position of the rank0-th 0-bit (1-indexed).

Parameters
rank01-based rank of the 0-bit to select.
Returns
Bit index, or size() if rank0 is out of range.

◆ select_impl()

template<StorageImplementation MetadataStorage = AlignedStorage>
uint64_t pixie::RankSelectSupport< MetadataStorage >::select_impl ( size_t rank) const
inline

Rank of 0s up to position pos (exclusive).

Parameters
posBit index in [0, size()].
Returns
Number of 0s in [0, pos).

The documentation for this class was generated from the following file: