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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

use bitarray::BitArray;
let mut array = BitArray::new([1, 2]);
assert_eq!(*array, [1, 2]);

The resulting type after dereferencing.

Dereferences the value.

use bitarray::BitArray;
let mut array = BitArray::zeros();
array[0] = 1;
array[1] = 2;
assert_eq!(*array, [1, 2]);

Mutably dereferences the value.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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.