Struct vers_vecs::bit_vec::fast_rs_vec::RsVec
source · pub struct RsVec { /* private fields */ }Expand description
A bitvector that supports constant-time rank and select queries and is optimized for fast queries.
The bitvector is stored as a vector of u64s. The bit-vector stores meta-data for constant-time
rank and select queries, which takes sub-linear additional space. The space overhead is
28 bits per 512 bits of user data (~5.47%).
Example
use vers_vecs::{BitVec, RsVec};
let mut bit_vec = BitVec::new();
bit_vec.append_word(u64::MAX);
let rs_vec = RsVec::from_bit_vec(bit_vec);
assert_eq!(rs_vec.rank1(64), 64);
assert_eq!(rs_vec.select1(64), 64);Implementations§
source§impl RsVec
impl RsVec
sourcepub fn from_bit_vec(vec: BitVec) -> RsVec
pub fn from_bit_vec(vec: BitVec) -> RsVec
sourcepub fn rank0(&self, pos: usize) -> usize
pub fn rank0(&self, pos: usize) -> usize
Return the 0-rank of the bit at the given position. The 0-rank is the number of 0-bits in the vector up to but excluding the bit at the given position. Calling this function with an index larger than the length of the bit-vector will report the total number of 0-bits in the bit-vector.
Parameters
pos: The position of the bit to return the rank of.
Compatibility
This function forcibly enables the popcnt x86 CPU feature.
sourcepub fn rank1(&self, pos: usize) -> usize
pub fn rank1(&self, pos: usize) -> usize
Return the 1-rank of the bit at the given position. The 1-rank is the number of 1-bits in the vector up to but excluding the bit at the given position. Calling this function with an index larger than the length of the bit-vector will report the total number of 1-bits in the bit-vector.
Parameters
pos: The position of the bit to return the rank of.
Compatibility
This function forcibly enables the popcnt x86 CPU feature.
sourcepub fn select0(&self, rank: usize) -> usize
pub fn select0(&self, rank: usize) -> usize
Return the position of the 0-bit with the given rank. See rank0.
The following holds:
select0(rank0(pos)) == pos
If the rank is larger than the number of 0-bits in the vector, the vector length is returned.
Compatibility
This function forcibly enables the bmi2 x86 CPU feature. If this feature is not available
on the CPU, this function will not work.
sourcepub fn select1(&self, rank: usize) -> usize
pub fn select1(&self, rank: usize) -> usize
Return the position of the 1-bit with the given rank. See rank1.
The following holds:
select1(rank1(pos)) == pos
If the rank is larger than the number of 1-bits in the bit-vector, the vector length is returned.
Compatibility
This function forcibly enables the bmi2 x86 CPU feature. If this feature is not available
on the CPU, this function will not work.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the length of the vector, i.e. the number of bits it contains.
sourcepub fn get(&self, pos: usize) -> Option<u64>
pub fn get(&self, pos: usize) -> Option<u64>
Return the bit at the given position. The bit takes the least significant
bit of the returned u64 word.
If the position is larger than the length of the vector, None is returned.
sourcepub fn get_unchecked(&self, pos: usize) -> u64
pub fn get_unchecked(&self, pos: usize) -> u64
Return the bit at the given position. The bit takes the least significant bit of the returned u64 word.
Panics
This function may panic if pos >= self.len() (alternatively, it may return garbage).