Struct sucds::bit_vectors::rank9sel::Rank9Sel
source · pub struct Rank9Sel { /* private fields */ }
Expand description
Rank/select data structure over bit vectors with Vigna’s rank9 and hinted selection techniques.
This builds rank/select indices on BitVector
taking
- 25% overhead of space for the rank index, and
- 3% overhead of space for the select index (together with the rank’s overhead).
Notes
In the default configuration, it does not build the select index for faster queires.
To accelerate the queries, set Self::select1_hints()
and Self::select0_hints()
.
Examples
use sucds::bit_vectors::{Rank9Sel, Access, Rank, Select};
let bv = Rank9Sel::from_bits([true, false, false, true])
.select1_hints()
.select0_hints();
assert_eq!(bv.len(), 4);
assert_eq!(bv.access(1), Some(false));
assert_eq!(bv.rank1(1), Some(1));
assert_eq!(bv.rank0(1), Some(0));
assert_eq!(bv.select1(1), Some(3));
assert_eq!(bv.select0(0), Some(1));
Credits
This is a yet another Rust port of succinct::rs_bit_vector.
References
- S. Vigna, “Broadword implementation of rank/select queries,” In WEA, 2008.
Implementations§
source§impl Rank9Sel
impl Rank9Sel
sourcepub fn select1_hints(self) -> Self
pub fn select1_hints(self) -> Self
Builds an index for faster select1.
sourcepub fn select0_hints(self) -> Self
pub fn select0_hints(self) -> Self
Builds an index for faster select0.
sourcepub fn from_bits<I>(bits: I) -> Selfwhere
I: IntoIterator<Item = bool>,
pub fn from_bits<I>(bits: I) -> Selfwhere I: IntoIterator<Item = bool>,
sourcepub const fn bit_vector(&self) -> &BitVector
pub const fn bit_vector(&self) -> &BitVector
Returns the reference of the internal bit vector.
sourcepub const fn rs_index(&self) -> &Rank9SelIndex
pub const fn rs_index(&self) -> &Rank9SelIndex
Returns the reference of the internal rank/select index.
Trait Implementations§
source§impl Access for Rank9Sel
impl Access for Rank9Sel
source§fn access(&self, pos: usize) -> Option<bool>
fn access(&self, pos: usize) -> Option<bool>
Returns the pos
-th bit, or None
if out of bounds.
Examples
use sucds::bit_vectors::{Rank9Sel, Access};
let bv = Rank9Sel::from_bits([true, false, false]);
assert_eq!(bv.access(0), Some(true));
assert_eq!(bv.access(1), Some(false));
assert_eq!(bv.access(2), Some(false));
assert_eq!(bv.access(3), None);
source§impl Build for Rank9Sel
impl Build for Rank9Sel
source§fn build_from_bits<I>(
bits: I,
_with_rank: bool,
with_select1: bool,
with_select0: bool
) -> Result<Self>where
I: IntoIterator<Item = bool>,
Self: Sized,
fn build_from_bits<I>( bits: I, _with_rank: bool, with_select1: bool, with_select0: bool ) -> Result<Self>where I: IntoIterator<Item = bool>, Self: Sized,
Creates a new vector from input bit stream bits
.
Arguments
bits
: Bit stream.with_rank
: Dummy.with_select1
: Flag to enableSelf::select1_hints()
.with_select0
: Flag to enableSelf::select0_hints()
.
Errors
Never.
source§impl PartialEq for Rank9Sel
impl PartialEq for Rank9Sel
source§impl Rank for Rank9Sel
impl Rank for Rank9Sel
source§fn rank1(&self, pos: usize) -> Option<usize>
fn rank1(&self, pos: usize) -> Option<usize>
Returns the number of ones from the 0-th bit to the pos-1
-th bit, or
None
if self.len() < pos
.
Complexity
Constant
Examples
use sucds::bit_vectors::{Rank9Sel, Rank};
let bv = Rank9Sel::from_bits([true, false, false, true]);
assert_eq!(bv.rank1(1), Some(1));
assert_eq!(bv.rank1(2), Some(1));
assert_eq!(bv.rank1(3), Some(1));
assert_eq!(bv.rank1(4), Some(2));
assert_eq!(bv.rank1(5), None);
source§fn rank0(&self, pos: usize) -> Option<usize>
fn rank0(&self, pos: usize) -> Option<usize>
Returns the number of zeros from the 0-th bit to the pos-1
-th bit, or
None
if self.len() < pos
.
Complexity
Constant
Examples
use sucds::bit_vectors::{Rank9Sel, Rank};
let bv = Rank9Sel::from_bits([true, false, false, true]);
assert_eq!(bv.rank0(1), Some(0));
assert_eq!(bv.rank0(2), Some(1));
assert_eq!(bv.rank0(3), Some(2));
assert_eq!(bv.rank0(4), Some(2));
assert_eq!(bv.rank0(5), None);
source§impl Select for Rank9Sel
impl Select for Rank9Sel
source§fn select1(&self, k: usize) -> Option<usize>
fn select1(&self, k: usize) -> Option<usize>
Searches the position of the k
-th bit set, or
None
if self.num_ones() <= k
.
Complexity
Logarithmic
Examples
use sucds::bit_vectors::{Rank9Sel, Select};
let bv = Rank9Sel::from_bits([true, false, false, true]).select1_hints();
assert_eq!(bv.select1(0), Some(0));
assert_eq!(bv.select1(1), Some(3));
assert_eq!(bv.select1(2), None);
source§fn select0(&self, k: usize) -> Option<usize>
fn select0(&self, k: usize) -> Option<usize>
Searches the position of the k
-th bit unset, or
None
if self.num_zeros() <= k
.
Complexity
Logarithmic
Examples
use sucds::bit_vectors::{Rank9Sel, Select};
let bv = Rank9Sel::from_bits([true, false, false, true]).select0_hints();
assert_eq!(bv.select0(0), Some(1));
assert_eq!(bv.select0(1), Some(2));
assert_eq!(bv.select0(2), None);