pub struct BitArrayVec { /* private fields */ }Expand description
A growable list of bit arrays implemented using a Vec<u8>.
The bit arrays contained in the BitArrayVec must all be the same size. BitArrayVec is very
memory efficient for small bit arrays for a small time tradeoff.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(4, 4);
bav.set(0, &[0]);
bav.set(1, &[1]);
bav.set(2, &[2]);
bav.set(3, &[3]);
assert_eq!(
bav.iter().collect::<Vec<Vec<u8>>>(),
vec![vec![0], vec![1], vec![2], vec![3]],
);Implementations§
Source§impl BitArrayVec
impl BitArrayVec
Sourcepub fn new(bit_count: usize, len: usize) -> Self
pub fn new(bit_count: usize, len: usize) -> Self
Constructs a new BitArrayVec with a certain number of bit arrays. All bit arrays are
initialized to all zeros.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let bav = BitArrayVec::new(5, 4);
assert_eq!(
bav.iter().collect::<Vec<Vec<u8>>>(),
vec![vec![0], vec![0], vec![0], vec![0]],
);Sourcepub fn from_elem(bit_count: usize, len: usize, bytes: &[u8]) -> Self
pub fn from_elem(bit_count: usize, len: usize, bytes: &[u8]) -> Self
Constructs a new BitArrayVec with a certain number of bit arrays. All bit arrays are
initialized to bytes.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let bav = BitArrayVec::from_elem(5, 4, &[1]);
assert_eq!(
bav.iter().collect::<Vec<Vec<u8>>>(),
vec![vec![1], vec![1], vec![1], vec![1]],
);Sourcepub fn with_capacity(bit_count: usize, len: usize) -> Self
pub fn with_capacity(bit_count: usize, len: usize) -> Self
Constructs a new, empty BitArrayVec with a certain capacity.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let bav = BitArrayVec::with_capacity(5, 4);Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Truncates a BitArrayVec, dropping excess elements.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(5, 4);
bav.truncate(2);
assert_eq!(bav.iter().collect::<Vec<Vec<u8>>>(), vec![vec![0], vec![0]]);Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more bit arrays to be inserted in the given
BitArrayVec.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(5, 4);
bav.reserve(10);
assert!(bav.capacity() >= 14);Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves capacity for at least additional more bit arrays to be inserted in the given
BitArrayVec. Allocates exactly enough space in the underlying Vec<u8>.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(5, 4);
bav.reserve_exact(10);
assert_eq!(bav.capacity(), 14);Sourcepub fn push(&mut self, bytes: &[u8])
pub fn push(&mut self, bytes: &[u8])
Pushes an element into the BitArrayVec.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(5, 1);
bav.push(&[1]);
assert_eq!(bav.pop(), &[1]);
assert_eq!(bav.pop(), &[0]);Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all elements in the BitVecArray, setting all bit arrays to zero.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::from_elem(5, 4, &[1]);
bav.clear();
assert_eq!(
bav.iter().collect::<Vec<Vec<u8>>>(),
vec![vec![0], vec![0], vec![0], vec![0]],
);Sourcepub fn iter(&self) -> BitArrayVecIter<'_> ⓘ
pub fn iter(&self) -> BitArrayVecIter<'_> ⓘ
Returns an iterator over the elements of the vector in order.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(5, 1);
bav.push(&[1]);
assert_eq!(bav.iter().collect::<Vec<Vec<u8>>>(), vec![vec![0], vec![1]]);Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the capacity of the BitArrayVec.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(5, 0);
bav.reserve_exact(10);
assert_eq!(bav.capacity(), 11);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the BitArrayVec.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(5, 1);
bav.push(&[1]);
assert_eq!(bav.len(), 2);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the BitArrayVec is empty.
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(5, 0);
assert!(bav.is_empty());
bav.push(&[1]);
assert!(!bav.is_empty());Sourcepub fn occupied_len(&self) -> usize
pub fn occupied_len(&self) -> usize
Returns the number of non-zero elements in the BitArrayVec;
§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;
let mut bav = BitArrayVec::new(5, 1);
bav.push(&[1]);
assert_eq!(bav.occupied_len(), 1);