Struct deepmesa_collections::bitvec::bitvec::BitVector[][src]

pub struct BitVector { /* fields omitted */ }
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);

Implementations

Creates an empty BitVector with a capacity or 128 bits.

Examples

use deepmesa::collections::BitVector;
let bv = BitVector::new();
assert_eq!(bv.capacity(), 128);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Performs the conversion.

Performs the conversion.

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

Performs the &= operation. Read more

Performs the &= operation. Read more

Performs the &= operation. Read more

Performs the &= operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Performs the |= operation. Read more

Performs the |= operation. Read more

Performs the |= operation. Read more

Performs the |= operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

Performs the ^= operation. Read more

Performs the ^= operation. Read more

Performs the ^= operation. Read more

Performs the ^= operation. Read more

Formats the value using the given formatter. Read more

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

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

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

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

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

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

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.