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.
RawVectornever panics from I/O errors.
Implementations§
Source§impl RawVector
impl RawVector
Sourcepub fn count_ones(&self) -> usize
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);Sourcepub fn new() -> RawVector
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);Sourcepub fn with_capacity(capacity: usize) -> RawVector
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);Sourcepub fn size_by_params(capacity: usize) -> usize
pub fn size_by_params(capacity: usize) -> usize
Sourcepub fn complement(&self) -> RawVector
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));
}Sourcepub fn resize(&mut self, new_len: usize, value: bool)
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);Sourcepub fn clear(&mut self)
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());Sourcepub fn reserve(&mut self, additional: usize)
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.
pub fn get_words(&self) -> &[u64]
Trait Implementations§
Source§impl AccessRaw for RawVector
impl AccessRaw for RawVector
Source§unsafe fn int(&self, bit_offset: usize, width: usize) -> u64
unsafe fn int(&self, bit_offset: usize, width: usize) -> u64
Source§unsafe fn word_unchecked(&self, index: usize) -> u64
unsafe fn word_unchecked(&self, index: usize) -> u64
AccessRaw::word without bounds checks. Read moreSource§fn is_mutable(&self) -> bool
fn is_mutable(&self) -> bool
true if the underlying data is mutable. Read more