Struct BitVector

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

A bit vector where each element is 1 bit.

§Example

let bv = sdsl::bit_vectors::BitVector::new(5, 1)?;
let result: Vec<_> = bv.iter().collect();
let expected = vec![1, 1, 1, 1, 1];
assert_eq!(result, expected);

For further examples see here.

Implementations§

Source§

impl BitVector

Source

pub fn new(size: usize, default_value: usize) -> Result<Self>

Construct a new bit vector.

§Arguments
  • size - Number of elements.
  • default_value - Default values for elements initialization.
Source

pub fn from_file(path: &PathBuf) -> Result<Self>

Load vector from file.

§Arguments
  • path - File path.
Source

pub fn is_empty(&self) -> bool

Returns true if the vector is empty, otherwise returns false.

Source

pub fn resize(&mut self, size: usize)

Resize the vector in terms of elements.

§Arguments
  • size - Target number of elements.
Source

pub fn len(&self) -> usize

The number of elements in the vector.

Source

pub fn max_size(&self) -> usize

Maximum size of the vector.

Source

pub fn bit_size(&self) -> usize

The number of bits in the vector.

Source

pub fn capacity(&self) -> usize

Returns the size of the occupied bits of the vector.

The capacity of a vector is greater or equal to the bit_size().

Source

pub fn data(&self) -> *const c_void

Constant pointer to the raw data of the vector.

Source

pub fn get_int(&self, index: usize, len: u8) -> usize

Get the integer value of the binary string of length len starting at position index in the vector.

§Arguments
  • index - Starting index of the binary representation of the integer.
  • len - Length of the binary representation of the integer.
§Example
//                          1, 2, 4, 8, 16
let bv = sdsl::bit_vector! {1, 1, 0, 0, 1};
let result = bv.get_int(0, 5);
let expected = 19; // = 1 + 2 + 16
assert_eq!(result, expected);
Source

pub fn set_int(&mut self, index: usize, value: usize, len: u8)

Set the bits from position index to index+len-1 to the binary representation of integer value.

The bit at position index represents the least significant bit (lsb), and the bit at position index+len-1 the most significant bit (msb) of value.

§Arguments
  • index - Starting index of the binary representation of value.
  • value - The integer to store in the vector.
  • len - The length used to store value in the vector.
Source

pub fn get(&self, index: usize) -> u8

Get the i-th element of the vector.

§Arguments
  • index - An index in range $ [0, \mathrm{len}()) $.
Source

pub fn set(&mut self, index: usize, value: usize)

Set the i-th element of the vector.

§Arguments
  • index - An index in range $ [0, \mathrm{len}()) $.
  • value - New element value.
Source

pub fn flip(&mut self)

Flip all bits.

Source

pub fn iter(&self) -> VectorIterator<'_, u8, Self>

Returns an iterator over the vector values.

Trait Implementations§

Source§

impl Clone for BitVector

Source§

fn clone(&self) -> Self

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 BitVector

Source§

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

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

impl Drop for BitVector

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl IntoIterator for BitVector

Source§

type Item = u8

The type of the elements being iterated over.
Source§

type IntoIter = VectorIntoIterator<u8, BitVector>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for BitVector

Source§

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

Equality operator for two vectors.

Two int_vectors are equal if

  • capacities and sizes are equal and
  • width are equal and
  • the bits in the range [0..bit_size()-1] are equal.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for BitVector

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.