RawVector

Struct RawVector 

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

A contiguous growable array of bits and up to 64-bit integers based on Vec of u64 values.

There are no iterators over the vector, because it may contain items of varying widths.

§Notes

  • The unused part of the last integer is always set to 0.
  • The underlying vector may allocate but not use more integers than are strictly necessary.
  • RawVector never panics from I/O errors.

Implementations§

Source§

impl RawVector

Source

pub fn len(&self) -> usize

Returns the length of the vector in bits.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector is empty.

Source

pub fn capacity(&self) -> usize

Returns the capacity of the vector in bits.

Source

pub fn count_ones(&self) -> usize

Counts the number of ones in the bit array.

§Examples
use simple_sds_sbwt::raw_vector::{RawVector, AccessRaw};

let mut v = RawVector::with_len(137, false);
assert_eq!(v.count_ones(), 0);
v.set_bit(1, true); v.set_bit(33, true); v.set_bit(95, true); v.set_bit(123, true);
assert_eq!(v.count_ones(), 4);
Source

pub fn new() -> RawVector

Creates an empty vector.

§Examples
use simple_sds_sbwt::raw_vector::RawVector;

let v = RawVector::new();
assert!(v.is_empty());
assert_eq!(v.capacity(), 0);
Source

pub fn with_len(len: usize, value: bool) -> RawVector

Creates an initialized vector of specified length.

§Arguments
  • len: Length of the vector in bits.
  • value: Initialization value.
§Examples
use simple_sds_sbwt::raw_vector::RawVector;

let v = RawVector::with_len(137, false);
assert_eq!(v.len(), 137);
Source

pub fn with_capacity(capacity: usize) -> RawVector

Creates an empty vector with enough capacity for at least capacity bits.

§Examples
use simple_sds_sbwt::raw_vector::RawVector;

let v = RawVector::with_capacity(137);
assert!(v.capacity() >= 137);
Source

pub fn size_by_params(capacity: usize) -> usize

Returns the size of a serialized vector with the given capacity in u64 elements.

§Examples
use simple_sds_sbwt::raw_vector::RawVector;

assert_eq!(RawVector::size_by_params(247), 6);
Source

pub fn complement(&self) -> RawVector

Returns a copy of the vector with each bit flipped.

§Examples
use simple_sds_sbwt::raw_vector::{RawVector, AccessRaw};

let mut original = RawVector::with_len(137, false);
original.set_bit(1, true); original.set_bit(33, true);
unsafe { original.set_int(95, 456, 9); } original.set_bit(123, true);
let complement = original.complement();
for i in 0..137 {
    assert_eq!(!(complement.bit(i)), original.bit(i));
}
Source

pub fn resize(&mut self, new_len: usize, value: bool)

Resizes the vector to a specified length.

If new_len > self.len(), the new new_len - self.len() bits will be initialized. If new_len < self.len(), the vector is truncated.

§Arguments
  • new_len: New length of the vector in bits.
  • value: Initialization value.
§Examples
use simple_sds_sbwt::raw_vector::RawVector;

let mut v = RawVector::new();
v.resize(137, true);
let w = RawVector::with_len(137, true);
assert_eq!(v, w);
Source

pub fn clear(&mut self)

Clears the vector without freeing the data.

§Examples
use simple_sds_sbwt::raw_vector::RawVector;

let mut v = RawVector::with_len(137, true);
assert_eq!(v.len(), 137);
v.clear();
assert!(v.is_empty());
Source

pub fn reserve(&mut self, additional: usize)

Reserves space for storing at least self.len() + additional bits in the vector.

Does nothing if the capacity is already sufficient.

§Examples
use simple_sds_sbwt::raw_vector::RawVector;

let mut v = RawVector::with_len(137, false);
v.reserve(318);
assert!(v.capacity() >= 137 + 318);
§Panics

May panic if self.len() + additional + 63 > usize::MAX.

Source

pub fn get_words(&self) -> &[u64]

Trait Implementations§

Source§

impl AccessRaw for RawVector

Source§

fn bit(&self, bit_offset: usize) -> bool

Reads a bit from the array. Read more
Source§

unsafe fn int(&self, bit_offset: usize, width: usize) -> u64

Reads an integer from the container. Read more
Source§

fn word(&self, index: usize) -> u64

Reads a 64-bit word from the container. Read more
Source§

unsafe fn word_unchecked(&self, index: usize) -> u64

Unsafe version of AccessRaw::word without bounds checks. Read more
Source§

fn is_mutable(&self) -> bool

Returns true if the underlying data is mutable. Read more
Source§

fn set_bit(&mut self, bit_offset: usize, value: bool)

Writes a bit to the container. Read more
Source§

unsafe fn set_int(&mut self, bit_offset: usize, value: u64, width: usize)

Writes an integer to the container. Read more
Source§

impl AsRef<[u64]> for RawVector

Source§

fn as_ref(&self) -> &[u64]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<RawVector> for BitVector

Source§

fn as_ref(&self) -> &RawVector

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<RawVector> for IntVector

Source§

fn as_ref(&self) -> &RawVector

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for RawVector

Source§

fn clone(&self) -> RawVector

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 RawVector

Source§

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

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

impl Default for RawVector

Source§

fn default() -> RawVector

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

impl From<BitVector> for RawVector

Source§

fn from(source: BitVector) -> Self

Converts to this type from the input type.
Source§

impl From<IntVector> for RawVector

Source§

fn from(source: IntVector) -> Self

Converts to this type from the input type.
Source§

impl From<RawVector> for BitVector

Source§

fn from(data: RawVector) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for RawVector

Source§

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

Tests for self and other values to be equal, and is used by ==.
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 PopRaw for RawVector

Source§

fn pop_bit(&mut self) -> Option<bool>

Removes and returns the last bit from the container. Read more
Source§

unsafe fn pop_int(&mut self, width: usize) -> Option<u64>

Removes and returns the last width bits from the container as an integer. Read more
Source§

impl PushRaw for RawVector

Source§

fn push_bit(&mut self, value: bool)

Appends a bit to the container. Read more
Source§

unsafe fn push_int(&mut self, value: u64, width: usize)

Appends an integer to the container. Read more
Source§

impl Serialize for RawVector

Source§

fn serialize_header<T: Write>(&self, writer: &mut T) -> Result<()>

Serializes the header to the writer. Read more
Source§

fn serialize_body<T: Write>(&self, writer: &mut T) -> Result<()>

Serializes the body to the writer. Read more
Source§

fn load<T: Read>(reader: &mut T) -> Result<Self>

Loads the struct from the reader. Read more
Source§

fn size_in_elements(&self) -> usize

Returns the size of the serialized struct in u64 elements. Read more
Source§

fn serialize<T: Write>(&self, writer: &mut T) -> Result<()>

Serializes the struct to the writer. Read more
Source§

fn size_in_bytes(&self) -> usize

Returns the size of the serialized struct in bytes. Read more
Source§

impl Eq for RawVector

Source§

impl StructuralPartialEq for RawVector

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