BitVector

Struct BitVector 

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

A fast contiguous growable array of bits allocated on the heap that allows storing and manipulating an arbitrary number of bits. This collection is backed by a Vector<u8> which manages the underlying memory.

§Getting Started

To get started add the deepmesa dependency to Cargo.toml and the use declaration in your source.

[dependencies]
deepmesa = "0.6.0"
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(128);
bv.push(true);
bv.push(false);
bv.push(true);

assert_eq!(bv.get(0), Some(true));
assert_eq!(bv.get(1), Some(false));
assert_eq!(bv.get(2), Some(true));

In addition to the new() and with_capacity() methods, the bitvector! macro is also provided for convenient initialization.

§Examples

use deepmesa_collections::BitVector;
use deepmesa_collections::bitvector;

let bv = bitvector![0,1,1,0];
assert_eq!(bv.len(), 4);

§Memory Management

Memory is managed by an underlying Vec<u8> and all methods operate on bytes whenever possible for efficiency. Internally the BitVector maintains a count of the number of bits currently held by the BitVector and the actual number of bytes stored maybe greater than eight times the number of bits. All bits stored past the number of active bits are zeroed out but this is not guaranteed to be true in future versions of the BitVector and should be relied up for correctness.

The BitVector can also return mutable and immutable pointers and slices to the underlying Vec<u8>. Modifying the underlying Vector can cause undefined behavior in the BitVector.

§Slices

Slices are implemented by the BitSlice which is a view into a range within the BitVector. A BitSlice is a wrapper around a slice of bytes with the 4 most significant bits of the slice length used to store the bit offset into the first byte of the slice. The rest of the bits of the length are used to store the length of the slice in bits.

Here is an illustrative example for BitVector with 16 bits:

           0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
bitvec:  [ 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1 ]
slice start = 10 len = 6                 ^              ^
byte = 10/8 = 1 , offset = 10 % 8 = 2
offset bits = 0010
Slice pointer: 0011_0000 [ 48 bits ] 0000_0110

The MSB of the offset is unused and must be always set to zero because there is a constraint that the length must be no greater than isize::MAX and hence cannot use more than 63 bits.

Implementations§

Source§

impl BitVector

Source

pub fn new() -> BitVector

Creates an empty BitVector with a capacity or 128 bits.

§Examples
use deepmesa_collections::BitVector;
let bv = BitVector::new();
assert_eq!(bv.capacity(), 128);
Source

pub fn with_capacity(capacity_bits: usize) -> BitVector

Creates an empty BitVector with the specified capacity. If the specified capacity is not a multiple of 8, it is increased to be a multiple of 8

§Examples
use deepmesa_collections::BitVector;
let bv = BitVector::with_capacity(6);
assert_eq!(bv.capacity(), 8);
Source

pub fn capacity(&self) -> usize

Returns the number of bits this BitVector can hold before new memory is allocated.

§Examples
use deepmesa_collections::BitVector;
let bv = BitVector::with_capacity(22);
assert_eq!(bv.capacity(), 24);
Source

pub fn len(&self) -> usize

Returns the number of bits in the BitVector

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::with_capacity(22);
for _ in 0..5 {
    bv.push(true);
}
assert_eq!(bv.len(), 5);
Source

pub fn is_empty(&self) -> bool

Returns true if the BitVector contains no bits.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::with_capacity(22);
assert!(bv.is_empty());
bv.push(true);
assert!(!bv.is_empty());
Source

pub fn clear(&mut self)

Clears the BitVector, removing all the bits. This method has no effect on the allocated capacity of the BitVector.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::with_capacity(22);
for _ in 0..5 {
    bv.push(true);
}
assert_eq!(bv.len(), 5);
bv.clear();
assert_eq!(bv.len(), 0);
Source

pub fn truncate(&mut self, len: usize)

Source

pub fn iter(&self) -> Iter<'_>

Returns an iterator over the bits of this BitVector

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b101, None);

let mut iter = bv.iter();
assert_eq!(iter.next(), Some(true));
assert_eq!(iter.next(), Some(false));
assert_eq!(iter.next(), Some(true));
assert_eq!(iter.next(), None);
Source

pub fn iter_mut(&mut self) -> IterMut<'_>

Returns a mutable iterator that allows modifyingthe bits of this BitVector

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
bv.push_u8(0b1011_1100, Some(8));
bv.push_u8(0b0011_1001, Some(8));
let iter = bv.iter_mut();
for mut bit in iter {
    *bit = true;
}
assert_eq!(bv.read_u16(0), (0b1111_1111_1111_1111, 16));
Source

pub fn leading_ones(&self, start: usize) -> usize

Counts the number of bits from the specified start index to the first bit set to 0. Panics if start is non-zero and greater than or equal to the length of the BitVector.

Returns 0 if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.leading_ones(0), 0);

bv.push_u8(0b1111_1000, Some(8));
bv.push_u8(0b0011_1101, Some(8));

assert_eq!(bv.leading_ones(0), 5);
assert_eq!(bv.leading_ones(8), 0);
assert_eq!(bv.leading_ones(10), 4);
Source

pub fn leading_zeros(&self, start: usize) -> usize

Counts the number of bits from the specified start index to the first bit set to 1. Panics if start is non-zero and greater than or equal to the length of the BitVector.

Returns 0 if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.leading_zeros(0), 0);

bv.push_u8(0b0000_0111, Some(8));
bv.push_u8(0b1100_0010, Some(8));

assert_eq!(bv.leading_zeros(0), 5);
assert_eq!(bv.leading_zeros(8), 0);
assert_eq!(bv.leading_zeros(10), 4);
Source

pub fn trailing_ones(&self, start: usize) -> usize

Counts the number of bits from end of the BitVector to the specified start index or to the first bit set to 0 whichever is smaller. Panics if start is non-zero and greater than or equal to the length of the BitVector.

Returns 0 if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.trailing_ones(0), 0);

bv.push_u8(0b1111_1000, Some(8));
bv.push_u8(0b0011_1111, Some(8));

assert_eq!(bv.trailing_ones(0), 6);
assert_eq!(bv.trailing_ones(8), 6);
assert_eq!(bv.leading_ones(12), 4);
Source

pub fn trailing_zeros(&self, start: usize) -> usize

Counts the number of bits from end of the BitVector to the specified start index or to the first bit set to 1 whichever is smaller. Panics if start is non-zero and greater than or equal to the length of the BitVector.

Returns 0 if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.trailing_zeros(0), 0);

bv.push_u8(0b1111_1000, Some(8));
bv.push_u8(0b1100_0000, Some(8));

assert_eq!(bv.trailing_zeros(0), 6);
//assert_eq!(bv.trailing_zeros(8), 6);
//assert_eq!(bv.trailing_zeros(12), 4);
Source

pub fn count_ones(&self, start: usize) -> usize

Counts the number of bits from the specified start that are set to 1 in the BitVector. Panics if start is non-zero and greater than or equal to the length of the BitVector.

Returns 0 if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.count_ones(0), 0);

bv.push_u8(0b1111_1000, Some(8));
bv.push_u8(0b1100_0000, Some(8));

assert_eq!(bv.count_ones(0), 7);
assert_eq!(bv.count_ones(8), 2);
assert_eq!(bv.count_ones(12), 0);
Source

pub fn count_zeros(&self, start: usize) -> usize

Counts the number of bits from the specified start that are set to 0 in the BitVector. Panics if start is non-zero and greater than or equal to the length of the BitVector.

Returns 0 if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.count_zeros(0), 0);

bv.push_u8(0b1111_1000, Some(8));
bv.push_u8(0b0000_1111, Some(8));

assert_eq!(bv.count_zeros(0), 7);
assert_eq!(bv.count_zeros(8), 4);
assert_eq!(bv.count_zeros(12), 0);
Source

pub fn first_zero(&self, start: usize) -> Option<usize>

Returns the index of the first bit after the specified start that is set to 0. Returns None if the BitVector is empty or if there are no zero bits.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.first_zero(0), None);

bv.push_u8(0b1111_1000, Some(8));
bv.push_u8(0b0000_1011, Some(8));

assert_eq!(bv.first_zero(0), Some(5));
assert_eq!(bv.first_zero(8), Some(8));
assert_eq!(bv.first_zero(12), Some(13));
assert_eq!(bv.first_zero(14), None);
Source

pub fn first_one(&self, start: usize) -> Option<usize>

Returns the index of the first bit after the specified start that is set to 1. Returns None if the BitVector is empty or if there are no one bits.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.first_one(0), None);

bv.push_u8(0b0000_0111, Some(8));
bv.push_u8(0b1111_0100, Some(8));

assert_eq!(bv.first_one(0), Some(5));
assert_eq!(bv.first_one(8), Some(8));
assert_eq!(bv.first_one(12), Some(13));
assert_eq!(bv.first_one(14), None);
Source

pub fn last_zero(&self, start: usize) -> Option<usize>

Returns the index of the last bit set to 0 after the specified start. Returns None if the BitVector is empty or if there are no zero bits.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.last_zero(0), None);

bv.push_u8(0b1101_1011, Some(8));

assert_eq!(bv.last_zero(0), Some(5));
assert_eq!(bv.last_zero(6), None);
Source

pub fn last_one(&self, start: usize) -> Option<usize>

Returns the index of the last bit set to 1 after the specified start. Returns None if the BitVector is empty or if there are no one bits.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.last_one(0), None);

bv.push_u8(0b0010_0100, Some(8));

assert_eq!(bv.last_one(0), Some(5));
assert_eq!(bv.last_one(6), None);
Source

pub fn first(&self) -> Option<BitRef<'_, bool>>

Returns an immutable reference to the first bit in the BitVector or None if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.first(), None);

bv.push_u8(0b0010_0100, Some(8));

assert_eq!(bv.first().as_deref(), Some(&false));
Source

pub fn first_mut(&mut self) -> Option<BitRefMut<'_, bool>>

Returns a mutable reference to the first bit in the BitVector or None if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.first(), None);

bv.push_u8(0b0010_0100, Some(8));

assert_eq!(bv.first_mut().as_deref(), Some(&false));
*bv.first_mut().unwrap() = true;
assert_eq!(bv.first_mut().as_deref(), Some(&true));
Source

pub fn last(&self) -> Option<BitRef<'_, bool>>

Returns an immutable reference to the last bit in the BitVector or None if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.last(), None);

bv.push_u8(0b0010_0101, Some(8));

assert_eq!(bv.last().as_deref(), Some(&true));
Source

pub fn last_mut(&mut self) -> Option<BitRefMut<'_, bool>>

Returns a mutable reference to the last bit in the BitVector or None if the BitVector is empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
assert_eq!(bv.first(), None);

bv.push_u8(0b0010_0101, Some(8));

assert_eq!(bv.last_mut().as_deref(), Some(&true));
*bv.last_mut().unwrap() = false;
assert_eq!(bv.last_mut().as_deref(), Some(&false));
Source

pub fn iter_ones(&self) -> IterOnes<'_>

Iterates over all the bits in the BitVector that are set to 1.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
bv.push_u8(0b0010_0101, Some(8));

let mut iter = bv.iter_ones();
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(5));
assert_eq!(iter.next(), Some(7));
assert_eq!(iter.next(), None);
Source

pub fn iter_zeros(&self) -> IterZeros<'_>

Iterates over all the bits in the BitVector that are set to 0.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(20);
bv.push_u8(0b1101_1010, Some(8));

let mut iter = bv.iter_zeros();
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(5));
assert_eq!(iter.next(), Some(7));
assert_eq!(iter.next(), None);
Source

pub fn iter_u8(&self) -> IterU8<'_>

Returns an iterator that iterates over the BitVector 8 bits at a time. Each invocation of iter.next returns a u8 value and the number of bits read.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

The iterator returns None if there are no more bits to return

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u16(0b0101_1101_0011_1010, Some(16));

let mut iter = bv.iter_u8();
assert_eq!(iter.next(), Some((0b0101_1101, 8)));
assert_eq!(iter.next(), Some((0b0011_1010, 8)));
assert_eq!(iter.next(), None);
Source

pub fn iter_u16(&self) -> IterU16<'_>

Returns an iterator that iterates over the bitvector 16 bits at a time. Each invocation of iter.next returns a u16 value and the number of bits read.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

The iterator returns None if there are no more bits to return

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u16(0b0101_1101_0011_1010, Some(16));

let mut iter = bv.iter_u16();
assert_eq!(iter.next(), Some((0b0101_1101_0011_1010, 16)));
assert_eq!(iter.next(), None);
Source

pub fn iter_u32(&self) -> IterU32<'_>

Returns an iterator that iterates over the bitvector 32 bits at a time. Each invocation of iter.next returns a u32 value and the number of bits read.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

The iterator returns None if there are no more bits to return

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u16(0b0101_1101_0011_1010, Some(16));
bv.push_u16(0b1111_0011_1100_0000, Some(16));

let mut iter = bv.iter_u32();
assert_eq!(iter.next(), Some((0b0101_1101_0011_1010_1111_0011_1100_0000, 32)));
assert_eq!(iter.next(), None);
Source

pub fn iter_u64(&self) -> IterU64<'_>

Returns an iterator that iterates over the bitvector 64 bits at a time. Each invocation of iter.next returns a u64 value and the number of bits read.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

The iterator returns None if there are no more bits to return

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u64(u64::MAX, Some(64));

let mut iter = bv.iter_u64();
assert_eq!(iter.next(), Some((u64::MAX, 64)));
assert_eq!(iter.next(), None);
Source

pub fn iter_u128(&self) -> IterU128<'_>

Returns an iterator that iterates over the bitvector 128 bits at a time. Each invocation of iter.next returns a u128 value and the number of bits read.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

The iterator returns None if there are no more bits to return

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u64(u64::MAX, Some(64));
bv.push_u64(u64::MAX, Some(64));

let mut iter = bv.iter_u128();
assert_eq!(iter.next(), Some((u128::MAX, 128)));
assert_eq!(iter.next(), None);
Source

pub fn read_u8(&self, start: usize) -> (u8, usize)

Reads upto 8 bits from this BitVector into a u8 starting at the specified start position. This method will panic if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u8(0b0011_0110, Some(8));

let (val, read) = bv.read_u8(0);
assert_eq!(read, 8);
assert_eq!(val, 0b0011_0110);

let (val, read) = bv.read_u8(4);
assert_eq!(read, 4);
assert_eq!(val, 0b0000_0110);
Source

pub fn read_u16(&self, start: usize) -> (u16, usize)

Reads upto 16 bits from this BitVector into a u16 starting at the specified start position. This method will panic if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u16(0b0011_0110_1100_0011, Some(16));

let (val, read) = bv.read_u16(0);
assert_eq!(read, 16);
assert_eq!(val, 0b0011_0110_1100_0011);

let (val, read) = bv.read_u16(4);
assert_eq!(read, 12);
assert_eq!(val, 0b0000_0110_1100_0011);
Source

pub fn read_u32(&self, start: usize) -> (u32, usize)

Reads upto 32 bits from this BitVector into a u32 starting at the specified start position. This method will panic if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u16(0b0011_0110_1100_0011, Some(16));
bv.push_u16(0b1100_1010_0100_1100, Some(16));

let (val, read) = bv.read_u32(0);
assert_eq!(read, 32);
assert_eq!(val, 0b0011_0110_1100_0011_1100_1010_0100_1100);

let (val, read) = bv.read_u16(16);
assert_eq!(read, 16);
assert_eq!(val, 0b1100_1010_0100_1100);
Source

pub fn read_u64(&self, start: usize) -> (u64, usize)

Reads upto 64 bits from this BitVector into a u64 starting at the specified start position. This method will panic if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u16(0b0011_0110_1100_0011, Some(16));
bv.push_u16(0b1100_1010_0100_1100, Some(16));

let (val, read) = bv.read_u64(20);
assert_eq!(read, 12);
assert_eq!(val, 0b1010_0100_1100);

let (val, read) = bv.read_u64(16);
assert_eq!(read, 16);
assert_eq!(val, 0b1100_1010_0100_1100);
Source

pub fn read_u128(&self, start: usize) -> (u128, usize)

Reads upto 128 bits from this BitVector into a u128 starting at the specified start position. This method will panic if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
bv.push_u16(0b0011_0110_1100_0011, Some(16));
bv.push_u16(0b1100_1010_0100_1100, Some(16));

let (val, read) = bv.read_u128(20);
assert_eq!(read, 12);
assert_eq!(val, 0b1010_0100_1100);

let (val, read) = bv.read_u128(16);
assert_eq!(read, 16);
assert_eq!(val, 0b1100_1010_0100_1100);
Source

pub fn read_bits_u8(&self, start: usize, max_bits: usize) -> (u8, usize)

Reads upto max_bits bits from this BitVector into a u8 starting at the specified start position. This method will panic if max_bits is greater than 8 or if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

Here is an illustrative example for a bitvector with 8 bits.

  0 1 2 3 4 5 6 7
[ 0,0,1,1,0,1,1,0 ]
 MSB [_______] LSB
      ^ Start = 2

value read = 0b1101

Reading 4 bits from the start position of 2, results in a u8 value of decimal 13.

This method returns the read value as well as the number of bits read as a tuple.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
// Push 8 bits: 0b0011_0110
bv.push_u8(0b0011_0110, Some(8));

let (val, read) = bv.read_bits_u8(2, 4);
assert_eq!(read,4);
assert_eq!(val, 0b0000_1101);
assert_eq!(val, 13);
Source

pub fn read_bits_u16(&self, start: usize, max_bits: usize) -> (u16, usize)

Reads upto max_bits bits from this BitVector into a u16 starting at the specified start position. This method will panic if max_bits is greater than 16 or if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

Here is an illustrative example for a bitvector with 8 bits.

  0 1 2 3 4 5 6 7
[ 0,0,1,1,0,1,1,0 ]
 MSB [_______] LSB
      ^ Start = 2

value read = 0b1101

Reading 4 bits from the start position of 2, results in a u16 value of decimal 13.

This method returns the read value as well as the number of bits read as a tuple.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
// Push 8 bits: 0b0011_0110
bv.push_u8(0b0011_0110, Some(8));

let (val, read) = bv.read_bits_u16(2, 4);
assert_eq!(read,4);
assert_eq!(val, 0b0000_1101);
assert_eq!(val, 13);
Source

pub fn read_bits_u32(&self, start: usize, max_bits: usize) -> (u32, usize)

Reads upto max_bits bits from this BitVector into a u32 starting at the specified start position. This method will panic if max_bits is greater than 32 or if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

Here is an illustrative example for a bitvector with 8 bits.

  0 1 2 3 4 5 6 7
[ 0,0,1,1,0,1,1,0 ]
 MSB [_______] LSB
      ^ Start = 2

value read = 0b1101

Reading 4 bits from the start position of 2, results in a u32 value of decimal 13.

This method returns the read value as well as the number of bits read as a tuple.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
// Push 8 bits: 0b0011_0110
bv.push_u8(0b0011_0110, Some(8));

let (val, read) = bv.read_bits_u32(2, 4);
assert_eq!(read,4);
assert_eq!(val, 0b0000_1101);
assert_eq!(val, 13);
Source

pub fn read_bits_u64(&self, start: usize, max_bits: usize) -> (u64, usize)

Reads upto max_bits bits from this BitVector into a u64 starting at the specified start position. This method will panic if max_bits is greater than 64 or if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

Here is an illustrative example for a bitvector with 8 bits.

  0 1 2 3 4 5 6 7
[ 0,0,1,1,0,1,1,0 ]
 MSB [_______] LSB
      ^ Start = 2

value read = 0b1101

Reading 4 bits from the start position of 2, results in a u64 value of decimal 13.

This method returns the read value as well as the number of bits read as a tuple.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
// Push 8 bits: 0b0011_0110
bv.push_u8(0b0011_0110, Some(8));

let (val, read) = bv.read_bits_u64(2, 4);
assert_eq!(read,4);
assert_eq!(val, 0b0000_1101);
assert_eq!(val, 13);
Source

pub fn read_bits_u128(&self, start: usize, max_bits: usize) -> (u128, usize)

Reads upto max_bits bits from this BitVector into a u128 starting at the specified start position. This method will panic if max_bits is greater than 128 or if start is greater than or equal to the length of the BitVector.

The bits are read from the lower to the higher index from the BitVector and shifted right, so the bit at the lower index is the MSB of returned value while the bit at the highest index is the LSB.

Here is an illustrative example for a bitvector with 8 bits.

  0 1 2 3 4 5 6 7
[ 0,0,1,1,0,1,1,0 ]
 MSB [_______] LSB
      ^ Start = 2

value read = 0b1101

Reading 4 bits from the start position of 2, results in a u128 value of decimal 13.

This method returns the read value as well as the number of bits read as a tuple.

§Examples
use deepmesa_collections::BitVector;
let mut bv = BitVector::new();
// Push 8 bits: 0b0011_0110
bv.push_u8(0b0011_0110, Some(8));

let (val, read) = bv.read_bits_u128(2, 4);
assert_eq!(read,4);
assert_eq!(val, 0b0000_1101);
assert_eq!(val, 13);
Source

pub fn push_bits_u8( &mut self, val: u8, bit_count: usize, order: BitOrder, ) -> usize

Pushes at most count bits from the specified u8 val to the end of the BitVector. The bits to be pushed are counted depending on the order. If the count is equal to 8 the order is ignored and all bits are pushed from the MSB (bit position 7) to the LSB (bit position 0). If the count is less than 8, then the bits are pushed in the specified Order as follows:

If the order is Msb0, the leading count bits starting from the MSB (from bit position 7) are pushed to the end of the BitVector

If the order is Lsb0, then trailing count bits starting from the LSB (from bit position 0) are pushed to the end of the BitVector.

This method will panic, if the count is greater than 8. If the count is 0, then no bits are pushed and the method has no effect.

§Examples
use deepmesa_collections::BitVector;
use deepmesa_collections::bitvec::BitOrder;

let mut bv = BitVector::new();
let val:u8 = 0b1100_0101;
bv.push_bits_u8(val, 3, BitOrder::Msb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], true);
assert_eq!(bv[2], false);

bv.clear();
bv.push_bits_u8(val, 3, BitOrder::Lsb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
Source

pub fn push_bits_u16( &mut self, val: u16, bit_count: usize, order: BitOrder, ) -> usize

Pushes at most count bits from the specified u16 val to the end of the BitVector. The bits to be pushed are counted depending on the order. If the count is equal to 16 the order is ignored and all bits are pushed from the MSB (bit position 15) to the LSB (bit position 0). If the count is less than 16, then the bits are pushed in the specified Order as follows:

If the order is Msb0, the leading count bits starting from the MSB (from bit position 15) are pushed to the end of the BitVector

If the order is Lsb0, then trailing count bits starting from the LSB (from bit position 0) are pushed to the end of the BitVector.

This method will panic, if the count is greater than 16. If the count is 0, then no bits are pushed and the method has no effect.

§Examples
use deepmesa_collections::BitVector;
use deepmesa_collections::bitvec::BitOrder;

let mut bv = BitVector::new();
let val:u16 = 0b1100_0000_0000_0101;
bv.push_bits_u16(val, 3, BitOrder::Msb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], true);
assert_eq!(bv[2], false);

bv.clear();
bv.push_bits_u16(val, 3, BitOrder::Lsb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
Source

pub fn push_bits_u32( &mut self, val: u32, bit_count: usize, order: BitOrder, ) -> usize

Pushes at most count bits from the specified u32 val to the end of the BitVector. The bits to be pushed are counted depending on the order. If the count is equal to 32 the order is ignored and all bits are pushed from the MSB (bit position 31) to the LSB (bit position 0). If the count is less than 32, then the bits are pushed in the specified Order as follows:

If the order is Msb0, the leading count bits starting from the MSB (from bit position 31) are pushed to the end of the BitVector

If the order is Lsb0, then trailing count bits starting from the LSB (from bit position 0) are pushed to the end of the BitVector.

This method will panic, if the count is greater than 32. If the count is 0, then no bits are pushed and the method has no effect.

§Examples
use deepmesa_collections::BitVector;
use deepmesa_collections::bitvec::BitOrder;

let mut bv = BitVector::new();
let val:u32 = 0b1100_0000_0000_0000_0000_0000_0000_0101;
bv.push_bits_u32(val, 3, BitOrder::Msb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], true);
assert_eq!(bv[2], false);

bv.clear();
bv.push_bits_u32(val, 3, BitOrder::Lsb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
Source

pub fn push_bits_u64( &mut self, val: u64, bit_count: usize, order: BitOrder, ) -> usize

Pushes at most count bits from the specified u64 val to the end of the BitVector. The bits to be pushed are counted depending on the order. If the count is equal to 64 the order is ignored and all bits are pushed from the MSB (bit position 63) to the LSB (bit position 0). If the count is less than 64, then the bits are pushed in the specified Order as follows:

If the order is Msb0, the leading count bits starting from the MSB (from bit position 63) are pushed to the end of the BitVector

If the order is Lsb0, then trailing count bits starting from the LSB (from bit position 0) are pushed to the end of the BitVector.

This method will panic, if the count is greater than 64. If the count is 0, then no bits are pushed and the method has no effect.

§Examples
use deepmesa_collections::BitVector;
use deepmesa_collections::bitvec::BitOrder;

let mut bv = BitVector::new();
// 4 MSB bits are 1100 and 4 LSB bits are 0101
let val:u64 = 0xc0_00_00_00_00_00_00_05;
bv.push_bits_u64(val, 3, BitOrder::Msb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], true);
assert_eq!(bv[2], false);

bv.clear();
bv.push_bits_u64(val, 3, BitOrder::Lsb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
Source

pub fn push_bits_u128( &mut self, val: u128, bit_count: usize, order: BitOrder, ) -> usize

Pushes at most count bits from the specified u128 val to the end of the BitVector. The bits to be pushed are counted depending on the order. If the count is equal to 128 the order is ignored and all bits are pushed from the MSB (bit position 127) to the LSB (bit position 0). If the count is less than 128, then the bits are pushed in the specified Order as follows:

If the order is Msb0, the leading count bits starting from the MSB (from bit position 127) are pushed to the end of the BitVector

If the order is Lsb0, then trailing count bits starting from the LSB (from bit position 0) are pushed to the end of the BitVector.

This method will panic, if the count is greater than 128. If the count is 0, then no bits are pushed and the method has no effect.

§Examples
use deepmesa_collections::BitVector;
use deepmesa_collections::bitvec::BitOrder;

let mut bv = BitVector::new();
// 4 MSB bits are 1100 and 4 LSB bits are 0101
let val:u128 = 0xc0_00_00_00_00_00_00_00_00_00_00_00_00_00_00_05;
bv.push_bits_u128(val, 3, BitOrder::Msb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], true);
assert_eq!(bv[2], false);

bv.clear();
bv.push_bits_u128(val, 3, BitOrder::Lsb0);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
Source

pub fn push_u8(&mut self, val: u8, min_width: Option<usize>) -> usize

Pushes bits from the specified u8 val excluding the leading zeros unless the min_width is specified. The min_width is the minimum number of bits to push (including leading zeros for padding). If the min_width is specified, then leading zeros are pushed before pushing the bits in the u8 to the BitVector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
let val:u8 = 0b101;
bv.push_u8(val, None);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);

bv.clear();
bv.push_u8(val, Some(5));
assert_eq!(bv.len(), 5);
assert_eq!(bv[0], false);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
assert_eq!(bv[3], false);
assert_eq!(bv[4], true);
Source

pub fn push_u16(&mut self, val: u16, min_width: Option<usize>) -> usize

Pushes bits from the specified u16 val excluding the leading zeros unless the min_width is specified. The min_width is the minimum number of bits to push (including leading zeros for padding). If the min_width is specified, then leading zeros are pushed before pushing the bits in the u16 to the BitVector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
let val:u16 = 0b101;
bv.push_u16(val, None);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);

bv.clear();
bv.push_u16(val, Some(5));
assert_eq!(bv.len(), 5);
assert_eq!(bv[0], false);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
assert_eq!(bv[3], false);
assert_eq!(bv[4], true);
Source

pub fn push_u32(&mut self, val: u32, min_width: Option<usize>) -> usize

Pushes bits from the specified u32 val excluding the leading zeros unless the min_width is specified. The min_width is the minimum number of bits to push (including leading zeros for padding). If the min_width is specified, then leading zeros are pushed before pushing the bits in the u32 to the BitVector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
let val:u32 = 0b101;
bv.push_u32(val, None);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);

bv.clear();
bv.push_u32(val, Some(5));
assert_eq!(bv.len(), 5);
assert_eq!(bv[0], false);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
assert_eq!(bv[3], false);
assert_eq!(bv[4], true);
Source

pub fn push_u64(&mut self, val: u64, min_width: Option<usize>) -> usize

Pushes bits from the specified u64 val excluding the leading zeros unless the min_width is specified. The min_width is the minimum number of bits to push (including leading zeros for padding). If the min_width is specified, then leading zeros are pushed before pushing the bits in the u64 to the BitVector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
let val:u64 = 0b101;
bv.push_u64(val, None);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);

bv.clear();
bv.push_u64(val, Some(5));
assert_eq!(bv.len(), 5);
assert_eq!(bv[0], false);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
assert_eq!(bv[3], false);
assert_eq!(bv[4], true);
Source

pub fn push_u128(&mut self, val: u128, min_width: Option<usize>) -> usize

Pushes bits from the specified u128 val excluding the leading zeros unless the min_width is specified. The min_width is the minimum number of bits to push (including leading zeros for padding). If the min_width is specified, then leading zeros are pushed before pushing the bits in the u128 to the BitVector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
let val:u128 = 0b101;
bv.push_u128(val, None);
assert_eq!(bv.len(), 3);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);

bv.clear();
bv.push_u128(val, Some(5));
assert_eq!(bv.len(), 5);
assert_eq!(bv[0], false);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
assert_eq!(bv[3], false);
assert_eq!(bv[4], true);
Source

pub fn as_bitslice(&self) -> &BitSlice

Returns an immutable reference to a BitSlice containing all the bits of the BitVector. This call is equivalent to &bv[..].

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b1011_1100, None);
let slice = bv.as_bitslice();
assert_eq!(slice.len(), 8);
let slice = &bv[..];
assert_eq!(slice.len(), 8);
Source

pub fn as_mut_bitslice(&mut self) -> &mut BitSlice

Returns a mutable reference to a BitSlice containing all the bits of the BitVector. This call is equivalent to &mut bv[..].

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b1011_1100, None);
let slice = bv.as_mut_bitslice();
assert_eq!(slice.len(), 8);
let slice = &mut bv[..];
assert_eq!(slice.len(), 8);
Source

pub fn as_raw_slice(&self) -> &[u8]

Returns an immutable slice of the underlying Vec<u8> containing the u8 values that encode the bits of the BitVector. Reading the bytes directly from this raw slice is not recommended since the BitVector manages the bytes in the underlying Vector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b0100_1101, Some(8));
let raw_slice = bv.as_raw_slice();
assert_eq!(raw_slice.len(), 1);
assert_eq!(raw_slice, &[0x4D]);
Source

pub fn as_mut_raw_slice(&mut self) -> &mut [u8]

Returns a mutable slice of the underlying Vec<u8> containing the u8 values that encode the bits of the BitVector. Reading from or modifying the bytes directly in this raw slice is not recommended since the BitVector manages the bytes in the underlying Vector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b0100_1101, Some(8));
let raw_slice = bv.as_mut_raw_slice();
assert_eq!(raw_slice.len(), 1);
assert_eq!(raw_slice, &[0x4D]);
Source

pub fn as_raw_ptr(&self) -> *const u8

Returns a raw pointer to the underlying Vec<u8> containing the u8 values that encode the bits of the BitVector. Reading from the bytes directly from this raw pointer is not recommended since the BitVector manages the bytes in the underlying Vector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b0100_1101, Some(8));
let raw_ptr = bv.as_raw_ptr();
Source

pub fn as_mut_raw_ptr(&mut self) -> *mut u8

Returns a mutable raw pointer to the underlying Vec<u8> containing the u8 values that encode the bits of the BitVector. Reading from or writing to the bytes directly in this raw pointer is not recommended since the BitVector manages the bytes in the underlying Vector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b0100_1101, Some(8));
let raw_ptr = bv.as_mut_raw_ptr();
Source

pub fn append(&mut self, other: &mut BitVector)

Moves all the bits of other into self, leaving other empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b1101, None);
let mut other = BitVector::new();
other.push_u8(0b1111_0011, Some(8));
bv.append(&mut other);
assert_eq!(bv.len(), 12);
assert_eq!(other.len(), 0);
Source

pub fn extend_from_bitslice(&mut self, other: &BitSlice)

Copies all the bits from the specified BitSlice into the BitVector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b1101, None);
let mut other = BitVector::new();
other.push_u8(0b1111_0011, Some(8));
let other_slice = &other[..];
bv.extend_from_bitslice(other_slice);
assert_eq!(bv.len(), 12);
Source

pub fn from_bitslice(slice: &BitSlice) -> Self

Creates a new BitVector by copying the contents of the specified BitSlice.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.push_u8(0b1101, None);

let bv2 = BitVector::from_bitslice(&bv[..]);
assert_eq!(bv2.len(), 4);
Source

pub fn repeat(bit: bool, len: usize) -> Self

Creates a new BitVector with a bit repeated len times

§Examples
use deepmesa_collections::BitVector;

let bv = BitVector::repeat(true, 4);
assert_eq!(bv.len(), 4);
Source

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

Sets the bit at the given index to 1 if bit is true, otherwise clears it. Panic if the index exceeds the length

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(22);
bv.push(true);
bv.push(false);
bv.push(true);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
assert_eq!(bv[2], true);
bv.set(0, false);
bv.set(1, true);
bv.set(2, false);
assert_eq!(bv[0], false);
assert_eq!(bv[1], true);
assert_eq!(bv[2], false);
Source

pub fn get(&self, index: usize) -> Option<bool>

Returns a boolean value indicating whether the bit at the specified index is set or None if the index is greater than or equal to the number of bits in the BitVector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(22);
bv.push(true);
bv.push(true);
bv.push(false);
assert_eq!(bv.get(0), Some(true));
assert_eq!(bv.get(1), Some(true));
assert_eq!(bv.get(2), Some(false));
assert_eq!(bv.get(3), None);
Source

pub fn get_mut(&mut self, index: usize) -> Option<BitRefMut<'_, bool>>

Source

pub fn push(&mut self, bit: bool)

Pushes a single bit to the end of the BitVector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(22);
bv.push(true);
bv.push(false);
assert_eq!(bv[0], true);
assert_eq!(bv[1], false);
Source

pub fn pop(&mut self) -> Option<bool>

Removes the last bit from the BitVector or None if its empty.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::with_capacity(22);
bv.push(true);
bv.push(false);
bv.push(true);
assert_eq!(bv.get(0), Some(true));
assert_eq!(bv.get(1), Some(false));
assert_eq!(bv.get(2), Some(true));
assert_eq!(bv.pop(), Some(true));
assert_eq!(bv.get(2), None);
Source

pub fn fill(&mut self, bit: bool, count: usize) -> usize

Extends the BitVector by pushing the specified bit, count times to the end of the BitVector.

§Examples
use deepmesa_collections::BitVector;

let mut bv = BitVector::new();
bv.fill(true, 4);
assert_eq!(bv.len(), 4);

Trait Implementations§

Source§

impl AsMut<BitSlice> for BitVector

Source§

fn as_mut(&mut self) -> &mut BitSlice

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

impl AsRef<BitSlice> for BitVector

Source§

fn as_ref(&self) -> &BitSlice

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

impl BitAnd<&BitSlice> for BitVector

Source§

type Output = BitVector

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &BitSlice) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd<&BitVector> for BitVector

Source§

type Output = BitVector

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &BitVector) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd<bool> for BitVector

Source§

type Output = BitVector

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: bool) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd for BitVector

Source§

type Output = BitVector

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: BitVector) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAndAssign<&BitSlice> for BitVector

Source§

fn bitand_assign(&mut self, rhs: &BitSlice)

Performs the &= operation. Read more
Source§

impl BitAndAssign<&BitVector> for BitVector

Source§

fn bitand_assign(&mut self, rhs: &BitVector)

Performs the &= operation. Read more
Source§

impl BitAndAssign<bool> for BitVector

Source§

fn bitand_assign(&mut self, rhs: bool)

Performs the &= operation. Read more
Source§

impl BitAndAssign for BitVector

Source§

fn bitand_assign(&mut self, rhs: BitVector)

Performs the &= operation. Read more
Source§

impl BitOr<&BitSlice> for BitVector

Source§

type Output = BitVector

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &BitSlice) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr<&BitVector> for BitVector

Source§

type Output = BitVector

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &BitVector) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr<bool> for BitVector

Source§

type Output = BitVector

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: bool) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr for BitVector

Source§

type Output = BitVector

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: BitVector) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOrAssign<&BitSlice> for BitVector

Source§

fn bitor_assign(&mut self, rhs: &BitSlice)

Performs the |= operation. Read more
Source§

impl BitOrAssign<&BitVector> for BitVector

Source§

fn bitor_assign(&mut self, rhs: &BitVector)

Performs the |= operation. Read more
Source§

impl BitOrAssign<bool> for BitVector

Source§

fn bitor_assign(&mut self, rhs: bool)

Performs the |= operation. Read more
Source§

impl BitOrAssign for BitVector

Source§

fn bitor_assign(&mut self, rhs: BitVector)

Performs the |= operation. Read more
Source§

impl BitXor<&BitSlice> for BitVector

Source§

type Output = BitVector

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: &BitSlice) -> Self::Output

Performs the ^ operation. Read more
Source§

impl BitXor<&BitVector> for BitVector

Source§

type Output = BitVector

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: &BitVector) -> Self::Output

Performs the ^ operation. Read more
Source§

impl BitXor<bool> for BitVector

Source§

type Output = BitVector

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: bool) -> Self::Output

Performs the ^ operation. Read more
Source§

impl BitXor for BitVector

Source§

type Output = BitVector

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: BitVector) -> Self::Output

Performs the ^ operation. Read more
Source§

impl BitXorAssign<&BitSlice> for BitVector

Source§

fn bitxor_assign(&mut self, rhs: &BitSlice)

Performs the ^= operation. Read more
Source§

impl BitXorAssign<&BitVector> for BitVector

Source§

fn bitxor_assign(&mut self, rhs: &BitVector)

Performs the ^= operation. Read more
Source§

impl BitXorAssign<bool> for BitVector

Source§

fn bitxor_assign(&mut self, rhs: bool)

Performs the ^= operation. Read more
Source§

impl BitXorAssign for BitVector

Source§

fn bitxor_assign(&mut self, rhs: BitVector)

Performs the ^= operation. 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 Default for BitVector

Source§

fn default() -> Self

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

impl Index<Range<usize>> for BitVector

Source§

type Output = BitSlice

The returned type after indexing.
Source§

fn index(&self, range: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFrom<usize>> for BitVector

Source§

type Output = BitSlice

The returned type after indexing.
Source§

fn index(&self, range: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFull> for BitVector

Source§

type Output = BitSlice

The returned type after indexing.
Source§

fn index(&self, _: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeInclusive<usize>> for BitVector

Source§

type Output = BitSlice

The returned type after indexing.
Source§

fn index(&self, range: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeTo<usize>> for BitVector

Source§

type Output = BitSlice

The returned type after indexing.
Source§

fn index(&self, range: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeToInclusive<usize>> for BitVector

Source§

type Output = BitSlice

The returned type after indexing.
Source§

fn index(&self, range: RangeToInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for BitVector

Source§

type Output = bool

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<Range<usize>> for BitVector

Source§

fn index_mut(&mut self, range: Range<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFrom<usize>> for BitVector

Source§

fn index_mut(&mut self, range: RangeFrom<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFull> for BitVector

Source§

fn index_mut(&mut self, _: RangeFull) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeInclusive<usize>> for BitVector

Source§

fn index_mut(&mut self, range: RangeInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeTo<usize>> for BitVector

Source§

fn index_mut(&mut self, range: RangeTo<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeToInclusive<usize>> for BitVector

Source§

fn index_mut(&mut self, range: RangeToInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a BitVector

Source§

type Item = bool

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

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 Not for BitVector

Source§

type Output = BitVector

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more

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.