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

source

pub fn new(bv: BitVector) -> Self

Creates a new vector from input bit vector bv.

source

pub fn select1_hints(self) -> Self

Builds an index for faster select1.

source

pub fn select0_hints(self) -> Self

Builds an index for faster select0.

source

pub fn from_bits<I>(bits: I) -> Selfwhere I: IntoIterator<Item = bool>,

Creates a new vector from input bit stream bits.

Arguments
  • bits: Bit stream.
source

pub const fn bit_vector(&self) -> &BitVector

Returns the reference of the internal bit vector.

source

pub const fn rs_index(&self) -> &Rank9SelIndex

Returns the reference of the internal rank/select index.

source

pub const fn len(&self) -> usize

Returns the number of bits stored.

source

pub const fn is_empty(&self) -> bool

Checks if the vector is empty.

Trait Implementations§

source§

impl Access for Rank9Sel

source§

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

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,

Creates a new vector from input bit stream bits.

Arguments
Errors

Never.

source§

impl Clone for Rank9Sel

source§

fn clone(&self) -> Rank9Sel

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Rank9Sel

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Rank9Sel

source§

fn default() -> Rank9Sel

Returns the “default value” for a type. Read more
source§

impl NumBits for Rank9Sel

source§

fn num_bits(&self) -> usize

Returns the number of bits stored (just wrapping Self::len()).

source§

fn num_ones(&self) -> usize

Returns the number of bits set.

source§

fn num_zeros(&self) -> usize

Returns the number of bits unset.
source§

impl PartialEq for Rank9Sel

source§

fn eq(&self, other: &Rank9Sel) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rank for Rank9Sel

source§

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>

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

source§

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>

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);
source§

impl Serializable for Rank9Sel

source§

fn serialize_into<W: Write>(&self, writer: W) -> Result<usize>

Serializes the data structure into the writer, returning the number of serialized bytes. Read more
source§

fn deserialize_from<R: Read>(reader: R) -> Result<Self>

Deserializes the data structure from the reader. Read more
source§

fn size_in_bytes(&self) -> usize

Returns the number of bytes to serialize the data structure.
source§

fn size_of() -> Option<usize>

Returns the size of a primitive type in bytes (if the type is so).
source§

impl Eq for Rank9Sel

source§

impl StructuralEq for Rank9Sel

source§

impl StructuralPartialEq for Rank9Sel

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.