Skip to main content

RankSelectBitVec

Struct RankSelectBitVec 

Source
pub struct RankSelectBitVec { /* private fields */ }
Expand description

A bitvector with O(1) rank and O(log n) select support.

Uses u64 blocks with a superblock index every 512 bits. Rank queries use u64::count_ones() for popcount. Select uses binary search over superblocks.

Implementations§

Source§

impl RankSelectBitVec

Source

pub fn build(bits: &[bool]) -> Self

Build a bitvector from a slice of booleans.

Source

pub fn get(&self, i: usize) -> bool

Get the bit at position i.

§Panics

Panics if i >= len.

Source

pub fn rank1(&self, i: usize) -> usize

Count the number of 1-bits in positions [0, i).

Returns 0 if i == 0. Panics if i > len.

Source

pub fn rank0(&self, i: usize) -> usize

Count the number of 0-bits in positions [0, i).

Source

pub fn select1(&self, k: usize) -> Option<usize>

Find the position of the k-th 1-bit (1-indexed).

Returns None if there are fewer than k set bits.

Source

pub fn select0(&self, k: usize) -> Option<usize>

Find the position of the k-th 0-bit (1-indexed).

Returns None if there are fewer than k zero bits.

Source

pub fn len(&self) -> usize

Total number of bits in the bitvector.

Source

pub fn is_empty(&self) -> bool

Whether the bitvector has zero length.

Source

pub fn count_ones(&self) -> usize

Total number of 1-bits.

Source

pub fn count_zeros(&self) -> usize

Total number of 0-bits.

Trait Implementations§

Source§

impl Clone for RankSelectBitVec

Source§

fn clone(&self) -> RankSelectBitVec

Returns a duplicate 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 RankSelectBitVec

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.