Struct rsdict::RsDict

source ·
pub struct RsDict { /* private fields */ }
Expand description

Data structure for efficiently computing both rank and select queries

Implementations§

source§

impl RsDict

source

pub fn from_blocks(blocks: impl Iterator<Item = u64>) -> Self

Create a dictionary from a bitset, specified as an iterator of 64-bit blocks. This function is equivalent to pushing each bit one at a time but is much faster.

source

pub fn heap_size(&self) -> usize

Return the size of the heap allocations associated with the RsDict.

source

pub fn new() -> Self

Create a new RsDict with zero capacity.

source

pub fn with_capacity(n: usize) -> Self

Create a new RsDict with the given capacity preallocated.

source

pub fn rank(&self, pos: u64, bit: bool) -> u64

Non-inclusive rank: Count the number of bit values left of pos. Panics if pos is out-of-bounds.

source

pub fn bit_and_one_rank(&self, pos: u64) -> (bool, u64)

Query the posth bit (zero-indexed) of the underlying bit and the number of set bits to the left of pos in a single operation. This method is faster than calling get_bit(pos) and rank(pos, true) separately.

source

pub fn inclusive_rank(&self, pos: u64, bit: bool) -> u64

Inclusive rank: Count the number of bit values at indices less than or equal to pos. Panics if pos is out-of-bounds.

source

pub fn select(&self, rank: u64, bit: bool) -> Option<u64>

Compute the position of the rankth instance of bit (zero-indexed), returning None if there are not rank + 1 instances of bit in the array.

source

pub fn select0(&self, rank: u64) -> Option<u64>

Specialized version of RsDict::select for finding positions of zeros.

source

pub fn select1(&self, rank: u64) -> Option<u64>

Specialized version of RsDict::select for finding positions of ones.

source

pub fn len(&self) -> usize

Return the length of the underlying bitmap.

source

pub fn is_empty(&self) -> bool

Return whether the underlying bitmap is empty.

source

pub fn count_ones(&self) -> usize

Count the number of set bits in the underlying bitmap.

source

pub fn count_zeros(&self) -> usize

Count the number of unset bits in the underlying bitmap.

source

pub fn push(&mut self, bit: bool)

Push a bit at the end of the underlying bitmap.

source

pub fn get_bit(&self, pos: u64) -> bool

Query the posth bit (zero-indexed) of the underlying bitmap.

source

pub fn iter(&self) -> impl Iterator<Item = bool> + '_

Iterate over the bits in the bitset.

Trait Implementations§

source§

impl Clone for RsDict

source§

fn clone(&self) -> RsDict

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 RsDict

source§

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

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

impl Ord for RsDict

source§

fn cmp(&self, rhs: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for RsDict

source§

fn eq(&self, rhs: &Self) -> 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 PartialOrd for RsDict

source§

fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for RsDict

Auto Trait Implementations§

§

impl Freeze for RsDict

§

impl RefUnwindSafe for RsDict

§

impl Send for RsDict

§

impl Sync for RsDict

§

impl Unpin for RsDict

§

impl UnwindSafe for RsDict

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> 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> ToOwned for T
where 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 T
where 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 T
where 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.