#[repr(C)]pub struct BitVecSimd<A, const L: usize>{ /* private fields */ }Expand description
Representation of a BitVec
see the module’s document for examples and details.
Implementations§
Source§impl<A, const L: usize> BitVecSimd<A, L>
impl<A, const L: usize> BitVecSimd<A, L>
Sourcepub fn zeros(nbits: usize) -> Self
pub fn zeros(nbits: usize) -> Self
Create an empty bitvec with nbits initial elements.
Example:
use bitvec_simd::BitVec;
let bitvec = BitVec::zeros(10);
assert_eq!(bitvec.len(), 10);Sourcepub fn ones(nbits: usize) -> Self
pub fn ones(nbits: usize) -> Self
Create a bitvec containing all 0 .. nbits elements. Example:
use bitvec_simd::BitVec;
let bitvec = BitVec::ones(10);
assert_eq!(bitvec.len(), 10);Sourcepub fn from_bool_iterator<I: Iterator<Item = bool>>(i: I) -> Self
pub fn from_bool_iterator<I: Iterator<Item = bool>>(i: I) -> Self
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>>());Sourcepub fn from_slice(slice: &[usize]) -> Self
pub fn from_slice(slice: &[usize]) -> Self
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]);Sourcepub fn from_slice_copy(
slice: &[<A::Item as BitBlock<L>>::Element],
nbits: usize,
) -> Self
pub fn from_slice_copy( slice: &[<A::Item as BitBlock<L>>::Element], nbits: usize, ) -> Self
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);Sourcepub unsafe fn from_raw_copy(
ptr: *const <A::Item as BitBlock<L>>::Element,
buffer_len: usize,
nbits: usize,
) -> Self
pub unsafe fn from_raw_copy( ptr: *const <A::Item as BitBlock<L>>::Element, buffer_len: usize, nbits: usize, ) -> Self
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.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> 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);Sourcepub fn storage_len(&self) -> usize
pub fn storage_len(&self) -> usize
Length of underlining storage.
Sourcepub fn storage_capacity(&self) -> usize
pub fn storage_capacity(&self) -> usize
Capacity of underlining storage.
Sourcepub fn as_mut_ptr(&mut self) -> *mut A::Item
pub fn as_mut_ptr(&mut self) -> *mut A::Item
Returns a raw mutable pointer to the vector’s buffer.
Sourcepub fn spilled(&self) -> bool
pub fn spilled(&self) -> bool
Returns true if the data has spilled into a separate heap-allocated buffer.
Sourcepub fn resize(&mut self, nbits: usize, value: bool)
pub fn resize(&mut self, nbits: usize, value: bool)
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);Sourcepub fn shrink_to(&mut self, nbits: usize)
pub fn shrink_to(&mut self, nbits: usize)
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);Sourcepub fn set(&mut self, index: usize, flag: bool)
pub fn set(&mut self, index: usize, flag: bool)
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));Sourcepub unsafe fn set_raw_copy(
&mut self,
ptr: *mut A::Item,
buffer_len: usize,
nbits: usize,
)
pub unsafe fn set_raw_copy( &mut self, ptr: *mut A::Item, buffer_len: usize, nbits: usize, )
Copy content which ptr points to bitvec storage Highly unsafe
Sourcepub unsafe fn set_raw(
&mut self,
ptr: *mut A::Item,
buffer_len: usize,
capacity: usize,
nbits: usize,
)
pub unsafe fn set_raw( &mut self, ptr: *mut A::Item, buffer_len: usize, capacity: usize, nbits: usize, )
Directly set storage to ptr Highly unsafe
Sourcepub fn set_all_false(&mut self)
pub fn set_all_false(&mut self)
Set all items in bitvec to false
Sourcepub fn set_all_true(&mut self)
pub fn set_all_true(&mut self)
Set all items in bitvec to true
Sourcepub fn get(&self, index: usize) -> Option<bool>
pub fn get(&self, index: usize) -> Option<bool>
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);Sourcepub fn get_unchecked(&self, index: usize) -> bool
pub fn get_unchecked(&self, index: usize) -> bool
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);pub fn and(self, other: Self) -> Self
pub fn and_cloned(&self, other: &Self) -> Self
pub fn and_inplace(&mut self, other: &Self)
pub fn or(self, other: Self) -> Self
pub fn or_cloned(&self, other: &Self) -> Self
pub fn or_inplace(&mut self, other: &Self)
pub fn xor(self, other: Self) -> Self
pub fn xor_cloned(&self, other: &Self) -> Self
pub fn xor_inplace(&mut self, other: &Self)
Sourcepub fn difference(self, other: Self) -> Self
pub fn difference(self, other: Self) -> Self
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 ^ BExample:
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);pub fn difference_cloned(&self, other: &Self) -> Self
Sourcepub fn inverse(&self) -> Self
pub fn inverse(&self) -> Self
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
Sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
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);Sourcepub fn count_ones_before(&self, index: usize) -> usize
pub fn count_ones_before(&self, index: usize) -> usize
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);
}Sourcepub fn leading_zeros(&self) -> usize
pub fn leading_zeros(&self) -> usize
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);Sourcepub fn into_bools(self) -> Vec<bool>
pub fn into_bools(self) -> Vec<bool>
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])Sourcepub fn into_usizes(self) -> Vec<usize>
pub fn into_usizes(self) -> Vec<usize>
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§
Source§impl<A, const L: usize> BitAnd<&BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
impl<A, const L: usize> BitAnd<&BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
& operator.Source§impl<A, const L: usize> BitAnd<&BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitAnd<&BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§impl<A, const L: usize> BitAnd<&mut BitVecSimd<A, L>> for &BitVecSimd<A, L>
impl<A, const L: usize> BitAnd<&mut BitVecSimd<A, L>> for &BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
& operator.Source§impl<A, const L: usize> BitAnd<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitAnd<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§impl<A, const L: usize> BitAnd<BitVecSimd<A, L>> for &BitVecSimd<A, L>
impl<A, const L: usize> BitAnd<BitVecSimd<A, L>> for &BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
& operator.Source§impl<A, const L: usize> BitAnd<BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
impl<A, const L: usize> BitAnd<BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
& operator.Source§impl<A, const L: usize> BitAnd for &BitVecSimd<A, L>
impl<A, const L: usize> BitAnd for &BitVecSimd<A, L>
Source§impl<A, const L: usize> BitAnd for &mut BitVecSimd<A, L>
impl<A, const L: usize> BitAnd for &mut BitVecSimd<A, L>
Source§impl<A, const L: usize> BitAnd for BitVecSimd<A, L>
impl<A, const L: usize> BitAnd for BitVecSimd<A, L>
Source§impl<A, const L: usize> BitAndAssign<&BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitAndAssign<&BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§fn bitand_assign(&mut self, rhs: &BitVecSimd<A, L>)
fn bitand_assign(&mut self, rhs: &BitVecSimd<A, L>)
&= operation. Read moreSource§impl<A, const L: usize> BitAndAssign<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitAndAssign<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§fn bitand_assign(&mut self, rhs: &mut BitVecSimd<A, L>)
fn bitand_assign(&mut self, rhs: &mut BitVecSimd<A, L>)
&= operation. Read moreSource§impl<A, const L: usize> BitAndAssign for BitVecSimd<A, L>
impl<A, const L: usize> BitAndAssign for BitVecSimd<A, L>
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl<A, const L: usize> BitOr<&BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
impl<A, const L: usize> BitOr<&BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
| operator.Source§impl<A, const L: usize> BitOr<&BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitOr<&BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§impl<A, const L: usize> BitOr<&mut BitVecSimd<A, L>> for &BitVecSimd<A, L>
impl<A, const L: usize> BitOr<&mut BitVecSimd<A, L>> for &BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
| operator.Source§impl<A, const L: usize> BitOr<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitOr<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§impl<A, const L: usize> BitOr<BitVecSimd<A, L>> for &BitVecSimd<A, L>
impl<A, const L: usize> BitOr<BitVecSimd<A, L>> for &BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
| operator.Source§impl<A, const L: usize> BitOr<BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
impl<A, const L: usize> BitOr<BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
| operator.Source§impl<A, const L: usize> BitOr for &BitVecSimd<A, L>
impl<A, const L: usize> BitOr for &BitVecSimd<A, L>
Source§impl<A, const L: usize> BitOr for &mut BitVecSimd<A, L>
impl<A, const L: usize> BitOr for &mut BitVecSimd<A, L>
Source§impl<A, const L: usize> BitOr for BitVecSimd<A, L>
impl<A, const L: usize> BitOr for BitVecSimd<A, L>
Source§impl<A, const L: usize> BitOrAssign<&BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitOrAssign<&BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§fn bitor_assign(&mut self, rhs: &BitVecSimd<A, L>)
fn bitor_assign(&mut self, rhs: &BitVecSimd<A, L>)
|= operation. Read moreSource§impl<A, const L: usize> BitOrAssign<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitOrAssign<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§fn bitor_assign(&mut self, rhs: &mut BitVecSimd<A, L>)
fn bitor_assign(&mut self, rhs: &mut BitVecSimd<A, L>)
|= operation. Read moreSource§impl<A, const L: usize> BitOrAssign for BitVecSimd<A, L>
impl<A, const L: usize> BitOrAssign for BitVecSimd<A, L>
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl<A, const L: usize> BitXor<&BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
impl<A, const L: usize> BitXor<&BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
^ operator.Source§impl<A, const L: usize> BitXor<&BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitXor<&BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§impl<A, const L: usize> BitXor<&mut BitVecSimd<A, L>> for &BitVecSimd<A, L>
impl<A, const L: usize> BitXor<&mut BitVecSimd<A, L>> for &BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
^ operator.Source§impl<A, const L: usize> BitXor<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitXor<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§impl<A, const L: usize> BitXor<BitVecSimd<A, L>> for &BitVecSimd<A, L>
impl<A, const L: usize> BitXor<BitVecSimd<A, L>> for &BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
^ operator.Source§impl<A, const L: usize> BitXor<BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
impl<A, const L: usize> BitXor<BitVecSimd<A, L>> for &mut BitVecSimd<A, L>
Source§type Output = BitVecSimd<A, L>
type Output = BitVecSimd<A, L>
^ operator.Source§impl<A, const L: usize> BitXor for &BitVecSimd<A, L>
impl<A, const L: usize> BitXor for &BitVecSimd<A, L>
Source§impl<A, const L: usize> BitXor for &mut BitVecSimd<A, L>
impl<A, const L: usize> BitXor for &mut BitVecSimd<A, L>
Source§impl<A, const L: usize> BitXor for BitVecSimd<A, L>
impl<A, const L: usize> BitXor for BitVecSimd<A, L>
Source§impl<A, const L: usize> BitXorAssign<&BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitXorAssign<&BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§fn bitxor_assign(&mut self, rhs: &BitVecSimd<A, L>)
fn bitxor_assign(&mut self, rhs: &BitVecSimd<A, L>)
^= operation. Read moreSource§impl<A, const L: usize> BitXorAssign<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
impl<A, const L: usize> BitXorAssign<&mut BitVecSimd<A, L>> for BitVecSimd<A, L>
Source§fn bitxor_assign(&mut self, rhs: &mut BitVecSimd<A, L>)
fn bitxor_assign(&mut self, rhs: &mut BitVecSimd<A, L>)
^= operation. Read moreSource§impl<A, const L: usize> BitXorAssign for BitVecSimd<A, L>
impl<A, const L: usize> BitXorAssign for BitVecSimd<A, L>
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreSource§impl<A, const L: usize> Clone for BitVecSimd<A, L>
impl<A, const L: usize> Clone for BitVecSimd<A, L>
Source§fn clone(&self) -> BitVecSimd<A, L>
fn clone(&self) -> BitVecSimd<A, L>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more