Struct bitarray::BitArray [−][src]
#[repr(align(64))]pub struct BitArray<const B: usize> { pub bytes: [u8; B], }
Expand description
A constant sized array of bits. B
defines the number of bytes.
This has an alignment of 64 to maximize the efficiency of SIMD operations.
It will automatically utilize SIMD at runtime where possible.
Fields
bytes: [u8; B]
Implementations
Create a new BitArray
.
use bitarray::BitArray; let array = BitArray::new([0]); assert_eq!(*array.bytes(), [0]);
Create a new BitArray
with all zeros.
use bitarray::BitArray; let array = BitArray::zeros(); assert_eq!(array, BitArray::new([0])); assert_eq!(*array, [0]);
Retrieve the byte array of a BitArray
.
use bitarray::BitArray; let array = BitArray::new([1, 2]); assert_eq!(*array, [1, 2]);
Retrieve the mutable byte array of a BitArray
.
use bitarray::BitArray; let mut array = BitArray::new([1, 2]); array.bytes_mut()[0] = 3; assert_eq!(*array, [3, 2]);
Compute the hamming weight of the BitArray
.
use bitarray::BitArray; let array = BitArray::new([0xAA; 83]); assert_eq!(array.weight(), 4 * 83);
Compute the hamming distance to another BitArray
.
use bitarray::BitArray; // All the bits are different. let a = BitArray::new([0xAA; 65]); let b = BitArray::new([0x55; 65]); assert_eq!(a.distance(&b), 8 * 65); // None of the bits are different. let a = BitArray::new([0xAA; 65]); let b = BitArray::new([0xAA; 65]); assert_eq!(a.distance(&b), 0);
Trait Implementations
use bitarray::BitArray; let mut array = BitArray::new([1, 2]); assert_eq!(*array, [1, 2]);
use bitarray::BitArray; let mut array = BitArray::zeros(); array[0] = 1; array[1] = 2; assert_eq!(*array, [1, 2]);