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

impl<const B: usize> BitArray<B>[src]

pub fn new(bytes: [u8; B]) -> Self[src]

Create a new BitArray.

use bitarray::BitArray;
let array = BitArray::new([0]);
assert_eq!(*array.bytes(), [0]);

pub fn zeros() -> Self[src]

Create a new BitArray with all zeros.

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

pub fn bytes(&self) -> &[u8; B][src]

Retrieve the byte array of a BitArray.

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

pub fn bytes_mut(&mut self) -> &mut [u8; B][src]

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

pub fn weight(&self) -> usize[src]

Compute the hamming weight of the BitArray.

use bitarray::BitArray;
let array = BitArray::new([0xAA; 83]);
assert_eq!(array.weight(), 4 * 83);

pub fn distance(&self, other: &Self) -> usize[src]

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

impl<const B: usize> Clone for BitArray<B>[src]

fn clone(&self) -> BitArray<B>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<const B: usize> Debug for BitArray<B>[src]

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

Formats the value using the given formatter. Read more

impl<const B: usize> Deref for BitArray<B>[src]

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

type Target = [u8; B]

The resulting type after dereferencing.

fn deref(&self) -> &Self::Target[src]

Dereferences the value.

impl<const B: usize> DerefMut for BitArray<B>[src]

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

fn deref_mut(&mut self) -> &mut Self::Target[src]

Mutably dereferences the value.

impl<const B: usize> Hash for BitArray<B>[src]

fn hash<H: Hasher>(&self, state: &mut H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

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

impl<const B: usize> PartialEq<BitArray<B>> for BitArray<B>[src]

fn eq(&self, other: &Self) -> bool[src]

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<const B: usize> Copy for BitArray<B>[src]

impl<const B: usize> Eq for BitArray<B>[src]

Auto Trait Implementations

impl<const B: usize> Send for BitArray<B>

impl<const B: usize> Sync for BitArray<B>

impl<const B: usize> Unpin for BitArray<B>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.