Skip to main content

BitArrayVec

Struct BitArrayVec 

Source
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

Source

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]],
);
Source

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]],
);
Source

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);
Source

pub fn set(&mut self, index: usize, bytes: &[u8])

Sets the value at index index to bytes.

§Panics

Panics if attempt to set an index out-of-bounds.

§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;

let mut bav = BitArrayVec::new(5, 4);
bav.set(1, &[1]);

assert_eq!(bav.get(0), vec![0]);
assert_eq!(bav.get(1), vec![1]);
Source

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

Returns the value at index index.

§Panics

Panics if attempt to get an index out-of-bounds.

§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;

let mut bav = BitArrayVec::new(5, 4);
bav.set(1, &[1]);

assert_eq!(bav.get(0), vec![0]);
assert_eq!(bav.get(1), vec![1]);
Source

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]]);
Source

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);
Source

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);
Source

pub fn pop(&mut self) -> Vec<u8>

Returns and removes the last element of the BitVecArray.

§Panics

Panics if the BitVecArray is empty.

§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;

let mut bav = BitArrayVec::new(5, 2);

bav.set(1, &[1]);

assert_eq!(bav.pop(), &[1]);
assert_eq!(bav.pop(), &[0]);
Source

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]);
Source

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]],
);
Source

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]]);
Source

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);
Source

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);
Source

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());
Source

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);
Source

pub fn bit_count(&self) -> usize

Returns the number of bits in each bit array stored by the BitArrayVec.

§Examples
use probabilistic_collections::bit_array_vec::BitArrayVec;

let bav = BitArrayVec::new(5, 0);

assert_eq!(bav.bit_count(), 5);

Trait Implementations§

Source§

impl Debug for BitArrayVec

Source§

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

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

impl<'a> IntoIterator for &'a BitArrayVec

Source§

type IntoIter = BitArrayVecIter<'a>

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

type Item = Vec<u8>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for BitArrayVec

Source§

type IntoIter = BitArrayVecIntoIter

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

type Item = Vec<u8>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for BitArrayVec

Source§

fn eq(&self, other: &BitArrayVec) -> 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 StructuralPartialEq for BitArrayVec

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> 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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V