#[repr(C)]
pub struct BitVecSimd<A, const L: usize> where
    A: Array + Index<usize>,
    A::Item: BitContainer<L>, 
{ /* private fields */ }
Expand description

Representation of a BitVec

see the module’s document for examples and details.

Implementations

Create an empty bitvec with nbits initial elements. Example:

use bitvec_simd::BitVec;

let bitvec = BitVec::zeros(10);
assert_eq!(bitvec.len(), 10);

Create a bitvec containing all 0 .. nbits elements. Example:

use bitvec_simd::BitVec;

let bitvec = BitVec::ones(10);
assert_eq!(bitvec.len(), 10);

Create a bitvec from an Iterator of bool.

Example:

use bitvec_simd::BitVec;

let bitvec = BitVec::from_bool_iterator((0..10).map(|x| x % 2 == 0));
assert_eq!(bitvec.len(), 10);
assert_eq!(<BitVec as Into<Vec<bool>>>::into(bitvec), vec![true, false, true, false, true, false, true, false, true, false]);

let bitvec = BitVec::from_bool_iterator((0..1000).map(|x| x < 50));
assert_eq!(bitvec.len(), 1000);
assert_eq!(bitvec.get(49), Some(true));
assert_eq!(bitvec.get(50), Some(false));
assert_eq!(bitvec.get(999), Some(false));
assert_eq!(<BitVec as Into<Vec<bool>>>::into(bitvec), (0..1000).map(|x| x<50).collect::<Vec<bool>>());

Initialize from a set of integers.

Example:

use bitvec_simd::BitVec;

let bitvec = BitVec::from_slice(&[0,5,9]);
assert_eq!(<BitVec as Into<Vec<bool>>>::into(bitvec), vec![true, false, false, false, false, true, false, false, false, true]);

Initialize from a E slice. Data will be copied from the slice.

Example:

use bitvec_simd::BitVec;

let bitvec = BitVec::from_slice_copy(&[3], 3);
assert_eq!(bitvec.get(0), Some(true));
assert_eq!(bitvec.get(1), Some(true));
assert_eq!(bitvec.get(2), Some(false));
assert_eq!(bitvec.get(3), None);

Initialize from a raw buffer. Data will be copied from the buffer which [ptr] points to. The buffer can be released after initialization.

Safety

If any of the following conditions are violated, the result is Undefined Behavior:

  • ptr should be valid and point to an [allocated object] with length >= buffer_len

  • ptr.offset(buffer_len - 1), in bytes, cannot overflow an isize.

  • The offset being in bounds cannot rely on “wrapping around” the address space. That is, the infinite-precision sum, in bytes must fit in a usize.

Length of this bitvec.

To get the number of elements, use count_ones

Example:

use bitvec_simd::BitVec;

let bitvec = BitVec::ones(3);
assert_eq!(bitvec.len(), 3);

Length of underlining storage.

Capacity of underlining storage.

Returns a raw pointer to the vector’s buffer.

Returns a raw mutable pointer to the vector’s buffer.

Returns true if the data has spilled into a separate heap-allocated buffer.

Resize this bitvec to nbits in-place. If new length is greater than current length, value will be filled.

Example:

use bitvec_simd::BitVec;

let mut bitvec = BitVec::ones(3);
bitvec.resize(5, false);
assert_eq!(bitvec.len(), 5);
bitvec.resize(2, false);
assert_eq!(bitvec.len(), 2);

Shink this bitvec to new length in-place. Panics if new length is greater than original.

Example:

use bitvec_simd::BitVec;

let mut bitvec = BitVec::ones(3);
bitvec.shrink_to(2);
assert_eq!(bitvec.len(), 2);

Remove or add index to the set. If index > self.len, the bitvec will be expanded to index. Example:

use bitvec_simd::BitVec;

let mut bitvec = BitVec::zeros(10);
assert_eq!(bitvec.len(), 10);
bitvec.set(15, true);  
// now 15 has been added to the set, its total len is 16.
assert_eq!(bitvec.len(), 16);
assert_eq!(bitvec.get(15), Some(true));
assert_eq!(bitvec.get(14), Some(false));

Copy content which ptr points to bitvec storage Highly unsafe

Directly set storage to ptr Highly unsafe

Set all items in bitvec to false

Set all items in bitvec to true

Set all items in bitvec to flag

Check if index exists in current set.

  • If exists, return Some(true)
  • If index < current.len and element doesn’t exist, return Some(false).
  • If index >= current.len, return None.

Examlpe:

use bitvec_simd::BitVec;

let bitvec : BitVec = (0 .. 15).map(|x| x%3 == 0).into();
assert_eq!(bitvec.get(3), Some(true));
assert_eq!(bitvec.get(5), Some(false));
assert_eq!(bitvec.get(14), Some(false));
assert_eq!(bitvec.get(15), None);

Directly return a bool instead of an Option

  • If exists, return true.
  • If doesn’t exist, return false.
  • If index >= current.len, panic.

Examlpe:

use bitvec_simd::BitVec;

let bitvec : BitVec = (0 .. 15).map(|x| x%3 == 0).into();
assert_eq!(bitvec.get_unchecked(3), true);
assert_eq!(bitvec.get_unchecked(5), false);
assert_eq!(bitvec.get_unchecked(14), false);

difference operation

A.difference(B) calculates A\B, e.g.

A = [1,2,3], B = [2,4,5]
A\B = [1,3]

also notice that

A.difference(B) | B.difference(A) == A ^ B

Example:

use bitvec_simd::BitVec;

let bitvec: BitVec = (0 .. 5_000).map(|x| x % 2 == 0).into();
let bitvec2 : BitVec = (0 .. 5_000).map(|x| x % 3 == 0).into();
assert_eq!(bitvec.difference_cloned(&bitvec2) | bitvec2.difference_cloned(&bitvec), bitvec.xor_cloned(&bitvec2));
let bitvec3 : BitVec = (0 .. 5_000).map(|x| x % 2 == 0 && x % 3 != 0).into();
assert_eq!(bitvec.difference(bitvec2), bitvec3);

inverse every bits in the vector.

If your bitvec have len 1_000 and contains [1,5], after inverse it will contains 0, 2..=4, 6..=999

Count the number of elements existing in this bitvec.

Example:

use bitvec_simd::BitVec;

let bitvec: BitVec = (0..10_000).map(|x| x%2==0).into();
assert_eq!(bitvec.count_ones(), 5000);

let bitvec: BitVec = (0..30_000).map(|x| x%3==0).into();
assert_eq!(bitvec.count_ones(), 10_000);

Count the number of elements existing in this bitvec, before the specified index. Panics if index is invalid.

Example:

use bitvec_simd::BitVec;

let bitvec: BitVec = (0..10_000).map(|x| x%2==0).into();
assert_eq!(bitvec.count_ones_before(5000), 2500);

let bitvec: BitVec = (0..30_000).map(|x| x%3==0).into();
assert_eq!(bitvec.count_ones_before(10000), 3334);

let bitvec: BitVec = (0..1).map(|x| true).into();
assert_eq!(bitvec.count_ones_before(0), 0);
assert_eq!(bitvec.count_ones_before(1), 1);

let bitvec: BitVec = (0..10).map(|x| true).into();
for i in 0..10 {
    assert_eq!(bitvec.count_ones_before(i), i);
}

let bitvec: BitVec = (0..10).map(|x| x==0).into();
assert_eq!(bitvec.count_ones_before(0), 0);
for i in 1..10 {
    assert_eq!(bitvec.count_ones_before(i), 1);
}

let bitvec: BitVec = (0..31).map(|x| true).into();
assert_eq!(bitvec.count_ones_before(0), 0);
for i in 1..31 {
    assert_eq!(bitvec.count_ones_before(i), i);
}

let bitvec: BitVec = (0..32).map(|x| true).into();
assert_eq!(bitvec.count_ones_before(0), 0);
for i in 1..32 {
    assert_eq!(bitvec.count_ones_before(i), i);
}

Count the number of leading zeros in this bitvec.

Example:

use bitvec_simd::BitVec;

let mut bitvec = BitVec::zeros(10);
bitvec.set(3, true);
assert_eq!(bitvec.leading_zeros(), 6);

return true if contains at least 1 element

return true if contains self.len elements

return true if set is empty

Return true if set is empty. Totally the same with self.none()

Consume self and generate a Vec<bool> with length == self.len().

Example:

use bitvec_simd::BitVec;

let bitvec = BitVec::from_bool_iterator((0..10).map(|i| i % 3 == 0));
let bool_vec = bitvec.into_bools();
assert_eq!(bool_vec, vec![true, false, false, true, false, false, true, false, false, true])

Consume self and geterate a Vec<usize> which only contains the number exists in this set.

Example:

use bitvec_simd::BitVec;

let bitvec = BitVec::from_bool_iterator((0..10).map(|i| i%3 == 0));
let usize_vec = bitvec.into_usizes();
assert_eq!(usize_vec, vec![0,3,6,9]);

Trait Implementations

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

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

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

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

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

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

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

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

The returned type after indexing.

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

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

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

This method tests for !=.

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

This method tests for !=.

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

This method tests for !=.

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

This method tests for !=.

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

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.