Struct sucds::bit_vectors::darray::DArray
source · pub struct DArray { /* private fields */ }
Expand description
Constant-time select data structure over integer sets with the dense array technique.
Memory complexity
$u + o(u)
$ bits for a bit vector with $u
$ bits.
Notes
In the default configuration, this data structure supports only Self::select1()
.
If rank queries are needed, Self::enable_rank()
and Self::enable_select0()
must be set up.
Examples
use sucds::bit_vectors::{DArray, Access, Rank, Select};
let da = DArray::from_bits([true, false, false, true])
.enable_rank()
.enable_select0();
assert_eq!(da.len(), 4);
assert_eq!(da.access(1), Some(false));
assert_eq!(da.rank1(1), Some(1));
assert_eq!(da.rank0(1), Some(0));
assert_eq!(da.select1(1), Some(3));
assert_eq!(da.select0(0), Some(1));
Credits
This is a yet another Rust port of succinct::darray.
References
- D. Okanohara, and K. Sadakane, “Practical Entropy-Compressed Rank/Select Dictionary,” In ALENEX, 2007.
Implementations§
source§impl DArray
impl DArray
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 fn enable_rank(self) -> Self
pub fn enable_rank(self) -> Self
Builds an index to enable rank queries.
sourcepub fn enable_select0(self) -> Self
pub fn enable_select0(self) -> Self
Builds an index to enable select0.
sourcepub const fn has_rank(&self) -> bool
pub const fn has_rank(&self) -> bool
Checks if Self::enable_rank()
is set.
sourcepub const fn has_select0(&self) -> bool
pub const fn has_select0(&self) -> bool
Checks if Self::enable_select0()
is set.
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 s1_index(&self) -> &DArrayIndex
pub const fn s1_index(&self) -> &DArrayIndex
Returns the reference of the internal select1 index.
sourcepub const fn s0_index(&self) -> Option<&DArrayIndex>
pub const fn s0_index(&self) -> Option<&DArrayIndex>
Returns the reference of the internal select0 index.
sourcepub const fn r9_index(&self) -> Option<&Rank9SelIndex>
pub const fn r9_index(&self) -> Option<&Rank9SelIndex>
Returns the reference of the internal rank index.
Trait Implementations§
source§impl Build for DArray
impl Build for DArray
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
: Flag to enableSelf::enable_rank()
.with_select1
: Dummy.with_select0
: Flag to enableSelf::enable_select0()
.
Errors
Never.
source§impl PartialEq for DArray
impl PartialEq for DArray
source§impl Rank for DArray
impl Rank for DArray
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
Panics
It panics if the index is not built by Self::enable_rank()
.
Examples
use sucds::bit_vectors::{DArray, Rank};
let da = DArray::from_bits([true, false, false, true]).enable_rank();
assert_eq!(da.rank1(1), Some(1));
assert_eq!(da.rank1(2), Some(1));
assert_eq!(da.rank1(3), Some(1));
assert_eq!(da.rank1(4), Some(2));
assert_eq!(da.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
Panics
It panics if the index is not built by Self::enable_rank()
.
Examples
use sucds::bit_vectors::{DArray, Rank};
let da = DArray::from_bits([true, false, false, true]).enable_rank();
assert_eq!(da.rank0(1), Some(0));
assert_eq!(da.rank0(2), Some(1));
assert_eq!(da.rank0(3), Some(2));
assert_eq!(da.rank0(4), Some(2));
assert_eq!(da.rank0(5), None);
source§impl Select for DArray
impl Select for DArray
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
Constant
Examples
use sucds::bit_vectors::{DArray, Select};
let da = DArray::from_bits([true, false, false, true]);
assert_eq!(da.select1(0), Some(0));
assert_eq!(da.select1(1), Some(3));
assert_eq!(da.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
Constant
Panics
It panics if the index is not built by Self::enable_select0()
.
Examples
use sucds::bit_vectors::{DArray, Select};
let da = DArray::from_bits([true, false, false, true]).enable_select0();
assert_eq!(da.select0(0), Some(1));
assert_eq!(da.select0(1), Some(2));
assert_eq!(da.select0(2), None);