Skip to main content

BitVector

Struct BitVector 

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

A bitmap with rank and select, in both directions.

The monotone forward link of section 3.4 asks all four questions of one vector: rank0 and select1 answer forward, and select0 answers backward. That is the whole reason the monotone form replaces both a forward link and a backward adjacency rather than only the forward one.

Implementations§

Source§

impl BitVector

Source

pub fn new(words: Vec<u64>, len: usize) -> Result<Self>

Builds a vector over len bits held in words, least significant bit of word zero first.

§Errors

If words is not exactly the number of words len bits take, or if a bit is set in the tail past len. The second one matters: a set tail bit is counted by rank and found by select, so accepting it would mean a vector that answers questions about bits nobody wrote.

Source

pub fn len(&self) -> usize

Bits in the vector.

Source

pub fn is_empty(&self) -> bool

Whether the vector has no bits at all.

Source

pub fn ones(&self) -> u64

Bits set.

Source

pub fn zeros(&self) -> u64

Bits clear, within the length.

Source

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

Bits set strictly below at.

Source

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

Bits clear strictly below at.

Source

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

Where the nth set bit is, counting from zero, or None if there are not that many.

Source

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

Where the nth clear bit is, counting from zero, or None if there are not that many.

Source

pub fn bytes(&self) -> usize

Bytes this costs on disk, which is the bitmap and the rank index and not the samples.

Source

pub fn bytes_for(len: usize) -> usize

Bytes BitVector::write produces for a vector of len bits, whatever its bits are.

For a payload that puts something after a vector and has to find where it starts.

Source

pub fn write(&self, out: &mut Vec<u8>)

Appends the bitmap and its rank index.

Source

pub fn read(bytes: &[u8], len: usize) -> Result<Self>

Reads a vector of len bits from exactly the bytes BitVector::write produced.

The rank index is read rather than rebuilt, and then it is not checked against the bitmap. Checking would be the pass that reading it was meant to avoid. A torn index is a wrong answer from a structure section 3.1 says can be deleted without changing any answer, so the protection that matters is the section checksum above this layer, not a recount here.

§Errors

If the bytes are not the length len implies, or if the tail past len is not zero.

§Panics

It does not. chunks_exact hands out eight bytes and the conversion to an eight byte array is the one the compiler cannot see through.

Trait Implementations§

Source§

impl Clone for BitVector

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BitVector

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.