pub struct RankSelect<CC = Vec<u64>, VC = Vec<u64>, WC = [u64; 2]> {
pub counts: CC,
pub values: Bools<VC, WC>,
}Expand description
A store for maintaining Vec<bool> with fast rank and select access.
The design is to have u64 running counts for each block of 1024 bits,
which are roughly the size of a cache line. This is roughly 6% overhead,
above the bits themselves, which seems pretty solid.
Fields§
§counts: CCCounts of the number of cumulative set (true) bits, after each block of 1024 bits.
values: Bools<VC, WC>The bits themselves.
Implementations§
Source§impl<CC: BorrowIndexAs<u64>, VC: BorrowIndexAs<u64>> RankSelect<CC, VC>
impl<CC: BorrowIndexAs<u64>, VC: BorrowIndexAs<u64>> RankSelect<CC, VC>
Source§impl<CC: Len + IndexAs<u64>, VC: Len + IndexAs<u64>, WC: IndexAs<u64>> RankSelect<CC, VC, WC>
impl<CC: Len + IndexAs<u64>, VC: Len + IndexAs<u64>, WC: IndexAs<u64>> RankSelect<CC, VC, WC>
Sourcepub fn rank(&self, index: usize) -> usize
pub fn rank(&self, index: usize) -> usize
The number of set bits strictly preceding index.
This number is accumulated first by reading out of self.counts at the correct position,
then by summing the ones in strictly prior u64 entries, then by counting the ones in the
masked u64 in which the bit lives.
Sourcepub fn select(&self, rank: u64) -> Option<usize>
pub fn select(&self, rank: u64) -> Option<usize>
The position of the rank-th set bit (0-indexed), if it exists.
select(0) returns the position of the first set bit. In general,
select(rank(p)) == p when p is the position of a set bit, mirroring
the convention of Self::rank (which counts bits strictly before
its argument).
Trait Implementations§
Source§impl<'a, CC: AsBytes<'a>, VC: AsBytes<'a>> AsBytes<'a> for RankSelect<CC, VC, &'a [u64]>
impl<'a, CC: AsBytes<'a>, VC: AsBytes<'a>> AsBytes<'a> for RankSelect<CC, VC, &'a [u64]>
Source§impl<CC: Clone, VC: Clone, WC: Clone> Clone for RankSelect<CC, VC, WC>
impl<CC: Clone, VC: Clone, WC: Clone> Clone for RankSelect<CC, VC, WC>
Source§fn clone(&self) -> RankSelect<CC, VC, WC>
fn clone(&self) -> RankSelect<CC, VC, WC>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<CC: Default, VC: Default, WC: Default> Default for RankSelect<CC, VC, WC>
impl<CC: Default, VC: Default, WC: Default> Default for RankSelect<CC, VC, WC>
Source§fn default() -> RankSelect<CC, VC, WC>
fn default() -> RankSelect<CC, VC, WC>
Source§impl<'a, CC: FromBytes<'a>, VC: FromBytes<'a>> FromBytes<'a> for RankSelect<CC, VC, &'a [u64]>
impl<'a, CC: FromBytes<'a>, VC: FromBytes<'a>> FromBytes<'a> for RankSelect<CC, VC, &'a [u64]>
Source§const SLICE_COUNT: usize
const SLICE_COUNT: usize
Source§fn from_bytes(bytes: &mut impl Iterator<Item = &'a [u8]>) -> Self
fn from_bytes(bytes: &mut impl Iterator<Item = &'a [u8]>) -> Self
self from a sequence of correctly aligned and sized bytes slices. Read moreSource§fn from_store(store: &DecodedStore<'a>, offset: &mut usize) -> Self
fn from_store(store: &DecodedStore<'a>, offset: &mut usize) -> Self
Source§impl<CC: PartialEq, VC: PartialEq, WC: PartialEq> PartialEq for RankSelect<CC, VC, WC>
impl<CC: PartialEq, VC: PartialEq, WC: PartialEq> PartialEq for RankSelect<CC, VC, WC>
Source§fn eq(&self, other: &RankSelect<CC, VC, WC>) -> bool
fn eq(&self, other: &RankSelect<CC, VC, WC>) -> bool
self and other values to be equal, and is used by ==.