pub struct BitVec { /* private fields */ }Expand description
A simple bit vector that does not support rank and select queries. Bits are stored in little-endian order, i.e. the least significant bit is stored first. The bit vector is stored as a sequence of 64 bit limbs. The last limb may be partially filled.
The bit vector has a wide range of constructors that allow for easy creation from various
sources.
Among them are constructors for creating an empty vector (BitVec::new),
creating one from single bits of various integer types (BitVec::from_bits and variations),
creating limbs from u64 values directly (BitVec::from_limbs and variations),
or packing a sequence of numerical values into a dense bit sequence
(BitVec::pack_sequence_u64 and variations).
The bit vector can be modified after creation (e.g. by appending bits or words, flipping, or setting bits). Bits can be accessed by position, and multiple bits can be accessed at once. Bits can be dropped from the end.
§Example
use vers_vecs::{BitVec, RsVec};
let mut bit_vec = BitVec::new();
bit_vec.append_bit(0u64);
bit_vec.append_bit_u32(1u32);
bit_vec.append_word(0b1010_1010_1010_1010u64); // appends exactly 64 bits
assert_eq!(bit_vec.len(), 66);
assert_eq!(bit_vec.get(0), Some(0u64));
assert_eq!(bit_vec.get(1), Some(1u64));Implementations§
Source§impl BitVec
impl BitVec
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new empty bit vector with the given capacity.
The capacity is measured in bits.
The bit vector will be able to hold at least capacity bits without reallocating.
More memory may be allocated according to the underlying allocation strategy.
Sourcepub fn from_zeros(len: usize) -> Self
pub fn from_zeros(len: usize) -> Self
Create a new bit vector with all zeros and the given length. The length is measured in bits.
Sourcepub fn from_ones(len: usize) -> Self
pub fn from_ones(len: usize) -> Self
Create a new bit vector with all ones and the given length. The length is measured in bits.
Sourcepub fn from_bits(bits: &[u8]) -> Self
pub fn from_bits(bits: &[u8]) -> Self
Construct a bit vector from a set of bits given as distinct u8 values. The constructor will take the least significant bit from each value and append it to a bit vector. All other bits are ignored.
See also: from_bits_u16, from_bits_u32, from_bits_u64, from_bits_iter
§Example
use vers_vecs::BitVec;
let bits: &[u8] = &[1, 0, 1, 1, 1, 1];
let bv = BitVec::from_bits(&bits);
assert_eq!(bv.len(), 6);
assert_eq!(bv.get_bits(0, 6), Some(0b111101u64));Sourcepub fn from_bits_u16(bits: &[u16]) -> Self
pub fn from_bits_u16(bits: &[u16]) -> Self
Construct a bit vector from a set of bits given as distinct u16 values. The constructor will take the least significant bit from each value and append it to a bit vector. All other bits are ignored.
See also: from_bits, from_bits_u32, from_bits_u64, from_bits_iter
Sourcepub fn from_bits_u32(bits: &[u32]) -> Self
pub fn from_bits_u32(bits: &[u32]) -> Self
Construct a bit vector from a set of bits given as distinct u32 values. The constructor will take the least significant bit from each value and append it to a bit vector. All other bits are ignored.
See also: from_bits, from_bits_u16, from_bits_u64, from_bits_iter
Sourcepub fn from_bits_u64(bits: &[u64]) -> Self
pub fn from_bits_u64(bits: &[u64]) -> Self
Construct a bit vector from a set of bits given as distinct u64 values. The constructor will take the least significant bit from each value and append it to a bit vector. All other bits are ignored.
See also: from_bits, from_bits_u16, from_bits_u32, from_bits_iter
Sourcepub fn from_bits_iter<I, E>(iter: I) -> Self
pub fn from_bits_iter<I, E>(iter: I) -> Self
Construct a bit vector from an iterator of bits. The constructor will take the least significant bit from each value and append it to a bit vector. All other bits are ignored. The iterator must yield values that can be converted into u64 values.
See also: from_bits, from_bits_u16, from_bits_u32, from_bits_u64
§Example
use vers_vecs::BitVec;
let bits = [true, false, true, true, true, true];
let bv = BitVec::from_bits_iter(bits.iter().copied());
let bits = [0b1u8, 0b0, 0b1, 0b1, 0b1, 0b1];
let bv2 = BitVec::from_bits_iter(bits.iter().copied());
assert_eq!(bv.len(), 6);
assert_eq!(bv.get_bits(0, 6), Some(0b111101u64));
assert_eq!(bv, bv2);Sourcepub fn from_limbs(words: &[u64]) -> Self
pub fn from_limbs(words: &[u64]) -> Self
Construct a bit vector from a slice of u64 quad words. The quad words are interpreted as limbs of the bit vector (i.e. each quad word contributes 64 bits to the bit vector). Since the data is only cloned without any masking or transformation, this is one of the fastest ways to create a bit vector.
See also: from_vec, from_limbs_iter
§Example
use vers_vecs::BitVec;
let words = [0, 256, u64::MAX];
let bv = BitVec::from_limbs(&words);
assert_eq!(bv.len(), 192);
assert_eq!(bv.get_bits(0, 64), Some(0u64));
assert_eq!(bv.get(72), Some(1));
assert_eq!(bv.get_bits(128, 64), Some(u64::MAX));Sourcepub fn from_limbs_iter<I, E>(iter: I) -> Self
pub fn from_limbs_iter<I, E>(iter: I) -> Self
Construct a bit vector from an iterator of u64 quad words. The quad words are interpreted as limbs of the bit vector (i.e. each quad word contributes 64 bits to the bit vector). Since the data is only cloned without any masking or transformation, this is one of the fastest ways to create a bit vector.
See also: from_limbs, from_vec
§Example
use std::iter::repeat;
use vers_vecs::BitVec;
let zeros = repeat(0xaaaaaaaaaaaaaaaau64).take(10);
let bv = BitVec::from_limbs_iter(zeros);
assert_eq!(bv.len(), 640);
for i in 0..640 {
assert_eq!(bv.get(i), Some((i % 2 == 1) as u64));
}Sourcepub fn from_vec(data: Vec<u64>) -> Self
pub fn from_vec(data: Vec<u64>) -> Self
Construct a bit vector from a vector of u64 quad words. The quad words are interpreted as limbs of the bit vector (i.e. each quad word contributes 64 bits to the bit vector). Since the data is moved without any masking or transformation, this is one of the fastest ways to create a bit vector.
See also: from_limbs, from_limbs_iter
§Example
use vers_vecs::BitVec;
let words = vec![0, 256, u64::MAX];
let bv = BitVec::from_vec(words);
assert_eq!(bv.len(), 192);
assert_eq!(bv.get_bits(0, 64), Some(0u64));
assert_eq!(bv.get(72), Some(1));
assert_eq!(bv.get_bits(128, 64), Some(u64::MAX));Sourcepub fn pack_sequence_u64(sequence: &[u64], bits_per_element: usize) -> Self
pub fn pack_sequence_u64(sequence: &[u64], bits_per_element: usize) -> Self
Construct a bit vector by packing a sequence of numerical values into a dense sequence.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The number of bits per element is given by bits_per_element.
The sequence is given as a slice of u64 values.
If the number of bits per element is smaller than 64, the function takes the
least significant bits of each element, and discards the rest.
If the number of bits per element is larger than 64, the function will pad the elements
with zeros.
The function will append the bits of each element to the bit vector in the order they are
given in the sequence (i.e. the first element takes bits 0..bits_per_element of the vector).
See also: pack_sequence_u32, pack_sequence_u16, pack_sequence_u8
§Example
use vers_vecs::BitVec;
let sequence = [0b1010u64, 0b1100u64, 0b1111u64];
let bv = BitVec::pack_sequence_u64(&sequence, 4);
assert_eq!(bv.len(), 12);
assert_eq!(bv.get_bits(0, 4), Some(0b1010u64));
assert_eq!(bv.get_bits(4, 4), Some(0b1100u64));
assert_eq!(bv.get_bits(8, 4), Some(0b1111u64));Sourcepub fn pack_sequence_u32(sequence: &[u32], bits_per_element: usize) -> Self
pub fn pack_sequence_u32(sequence: &[u32], bits_per_element: usize) -> Self
Construct a bit vector by packing a sequence of numerical values into a dense sequence.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The number of bits per element is given by bits_per_element.
The sequence is given as a slice of u32 values.
If the number of bits per element is smaller than 32, the function takes the
least significant bits of each element, and discards the rest.
If the number of bits per element is larger than 32, the function will pad the elements
with zeros.
The function will append the bits of each element to the bit vector in the order they are
given in the sequence (i.e. the first element takes bits 0..bits_per_element of the vector).
See also: pack_sequence_u64, pack_sequence_u16, pack_sequence_u8
§Example
use vers_vecs::BitVec;
let sequence = [0b1010u32, 0b1100u32, 0b1111u32];
let bv = BitVec::pack_sequence_u32(&sequence, 4);
assert_eq!(bv.len(), 12);
assert_eq!(bv.get_bits(0, 4), Some(0b1010u64));
assert_eq!(bv.get_bits(4, 4), Some(0b1100u64));
assert_eq!(bv.get_bits(8, 4), Some(0b1111u64));Sourcepub fn pack_sequence_u16(sequence: &[u16], bits_per_element: usize) -> Self
pub fn pack_sequence_u16(sequence: &[u16], bits_per_element: usize) -> Self
Construct a bit vector by packing a sequence of numerical values into a dense sequence.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The number of bits per element is given by bits_per_element.
The sequence is given as a slice of u16 values.
If the number of bits per element is smaller than 16, the function takes the
least significant bits of each element, and discards the rest.
If the number of bits per element is larger than 16, the function will pad the elements
with zeros.
The function will append the bits of each element to the bit vector in the order they are
given in the sequence (i.e. the first element takes bits 0..bits_per_element of the vector).
See also: pack_sequence_u64, pack_sequence_u32, pack_sequence_u8
§Example
use vers_vecs::BitVec;
let sequence = [0b1010u16, 0b1100u16, 0b1111u16];
let bv = BitVec::pack_sequence_u16(&sequence, 4);
assert_eq!(bv.len(), 12);
assert_eq!(bv.get_bits(0, 4), Some(0b1010u64));
assert_eq!(bv.get_bits(4, 4), Some(0b1100u64));
assert_eq!(bv.get_bits(8, 4), Some(0b1111u64));Sourcepub fn pack_sequence_u8(sequence: &[u8], bits_per_element: usize) -> Self
pub fn pack_sequence_u8(sequence: &[u8], bits_per_element: usize) -> Self
Construct a bit vector by packing a sequence of numerical values into a dense sequence.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The number of bits per element is given by bits_per_element.
The sequence is given as a slice of u8 values.
If the number of bits per element is smaller than 8, the function takes the
least significant bits of each element, and discards the rest.
If the number of bits per element is larger than 8, the function will pad the elements
with zeros.
The function will append the bits of each element to the bit vector in the order they are
given in the sequence (i.e. the first element takes bits 0..bits_per_element of the vector).
See also: pack_sequence_u64, pack_sequence_u32, pack_sequence_u16
§Example
use vers_vecs::BitVec;
let sequence = [0b1010u8, 0b1100u8, 0b1111u8];
let bv = BitVec::pack_sequence_u8(&sequence, 4);
assert_eq!(bv.len(), 12);
assert_eq!(bv.get_bits(0, 4), Some(0b1010u64));
assert_eq!(bv.get_bits(4, 4), Some(0b1100u64));
assert_eq!(bv.get_bits(8, 4), Some(0b1111u64));Sourcepub fn append(&mut self, bit: bool)
pub fn append(&mut self, bit: bool)
Append a bit encoded as a bool to the bit vector, where true means 1 and false means 0.
See also: append_bit, append_bit_u32, append_bit_u16, append_bit_u8, append_word
§Example
use vers_vecs::BitVec;
let mut bv = BitVec::new();
bv.append(true);
assert_eq!(bv.len(), 1);
assert_eq!(bv.get(0), Some(1));Sourcepub fn drop_last(&mut self, n: usize)
pub fn drop_last(&mut self, n: usize)
Drop the last n bits from the bit vector. If more bits are dropped than the bit vector contains, the bit vector is cleared.
§Example
use vers_vecs::BitVec;
let mut bv = BitVec::from_bits(&[1, 0, 1, 1, 1, 1]);
bv.drop_last(3);
assert_eq!(bv.len(), 3);
assert_eq!(bv.get_bits(0, 3), Some(0b101u64));
bv.drop_last(4);
assert!(bv.is_empty());Sourcepub fn append_bit(&mut self, bit: u64)
pub fn append_bit(&mut self, bit: u64)
Append a bit encoded in a u64. The least significant bit is appended to the bit vector. All other bits are ignored.
See also: append, append_bit_u32, append_bit_u16, append_bit_u8, append_word
§Example
use vers_vecs::BitVec;
let mut bv = BitVec::new();
bv.append_bit(1);
bv.append_bit(0);
assert_eq!(bv.len(), 2);
assert_eq!(bv.get(0), Some(1));
assert_eq!(bv.get(1), Some(0));Sourcepub fn append_bit_u32(&mut self, bit: u32)
pub fn append_bit_u32(&mut self, bit: u32)
Append a bit from a u32. The least significant bit is appended to the bit vector. All other bits are ignored.
See also: append, append_bit, append_bit_u16, append_bit_u8, append_word
Sourcepub fn append_bit_u16(&mut self, bit: u16)
pub fn append_bit_u16(&mut self, bit: u16)
Append a bit from a u16. The least significant bit is appended to the bit vector. All other bits are ignored.
See also: append, append_bit, append_bit_u32, append_bit_u8, append_word
Sourcepub fn append_bit_u8(&mut self, bit: u8)
pub fn append_bit_u8(&mut self, bit: u8)
Append a bit from a u8. The least significant bit is appended to the bit vector. All other bits are ignored.
See also: append, append_bit, append_bit_u32, append_bit_u16, append_word
Sourcepub fn append_word(&mut self, word: u64)
pub fn append_word(&mut self, word: u64)
Append a word to the bit vector. The bits are appended in little endian order (i.e. the first bit of the word is appended first).
See also: append, append_bit, append_bit_u32, append_bit_u16, append_bit_u8
§Example
use vers_vecs::BitVec;
let mut bv = BitVec::new();
bv.append_word(0b1010_1010_1010_1010u64);
assert_eq!(bv.len(), 64);
for i in 0..64 {
assert_eq!(bv.get(i), Some((0b1010_1010_1010_1010u64 >> i) & 1));
}Sourcepub fn append_bits(&mut self, bits: u64, len: usize)
pub fn append_bits(&mut self, bits: u64, len: usize)
Append multiple bits to the bit vector.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The number of bits to append is given by len. The bits are taken from the least
significant bits of bits.
All other bits are ignored.
§Example
use vers_vecs::BitVec;
let mut bv = BitVec::new();
bv.append_bits(0b1010_1010_1010_1010u64, 16);
assert_eq!(bv.len(), 16);
assert_eq!(bv.get_bits(0, 16), Some(0b1010_1010_1010_1010u64));§Panics
Panics if len is larger than 64.
Sourcepub fn append_bits_unchecked(&mut self, bits: u64, len: usize)
pub fn append_bits_unchecked(&mut self, bits: u64, len: usize)
Append multiple bits to the bit vector.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The number of bits to append is given by len. The bits are taken from the least
significant bits of bits.
This function does not check if len is larger than 64.
Furthermore, if the bit-vector has trailing bits that are not zero
(i.e. the length is not a multiple of 64, and those bits are partially set),
the function will OR the new data with the trailing bits, destroying the appended data.
This can happen, if a call append_bits[_unchecked](word, len) appends a word which has
set bits beyond the len - 1-th bit,
or if bits have been dropped from the bit vector using drop_last.
See append_bits for a checked version of this function.
§Panics
If len is larger than 64, the behavior is platform-dependent, and a processor
exception might be triggered.
Sourcepub fn extend_bitvec(&mut self, other: &Self)
pub fn extend_bitvec(&mut self, other: &Self)
Append the bits of another bit vector to the end of this vector. If this vector does not contain a multiple of 64 bits, the appended limbs need to be shifted to the left. This function is guaranteed to reallocate the underlying vector at most once.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the length of the bit vector. The length is measured in bits.
Sourcepub fn flip_bit_unchecked(&mut self, pos: usize)
pub fn flip_bit_unchecked(&mut self, pos: usize)
Sourcepub fn get(&self, pos: usize) -> Option<u64>
pub fn get(&self, pos: usize) -> Option<u64>
Return the bit at the given position. The bit is encoded in the least significant bit of a u64 value. If the position is larger than the length of the vector, None is returned.
See also: get_unchecked
§Example
use vers_vecs::BitVec;
let bv = BitVec::from_bits(&[1, 0, 1, 1, 1, 1]);
assert_eq!(bv.get(1), Some(0));
assert_eq!(bv.get(2), Some(1));Sourcepub fn get_unchecked(&self, pos: usize) -> u64
pub fn get_unchecked(&self, pos: usize) -> u64
Sourcepub fn set(&mut self, pos: usize, value: u64) -> Result<(), &str>
pub fn set(&mut self, pos: usize, value: u64) -> Result<(), &str>
Set the bit at the given position. The bit is encoded in the least significant bit of a u64 value.
See also: set_unchecked
§Example
use vers_vecs::BitVec;
let mut bv = BitVec::from_bits(&[1, 0, 1, 1, 1, 1]);
bv.set(1, 1).unwrap();
assert_eq!(bv.len(), 6);
assert_eq!(bv.get_bits(0, 6), Some(0b111111u64));§Errors
If the position is out of range, the function will return Err with an error message,
otherwise it will return an empty Ok.
Sourcepub fn set_unchecked(&mut self, pos: usize, value: u64)
pub fn set_unchecked(&mut self, pos: usize, value: u64)
Sourcepub fn is_bit_set(&self, pos: usize) -> Option<bool>
pub fn is_bit_set(&self, pos: usize) -> Option<bool>
Return whether the bit at the given position is set. If the position is larger than the length of the vector, None is returned.
See also: is_bit_set_unchecked
§Example
use vers_vecs::BitVec;
let bv = BitVec::from_bits(&[1, 0, 1, 1, 1, 1]);
assert!(!bv.is_bit_set(1).unwrap());
assert!(bv.is_bit_set(2).unwrap());Sourcepub fn is_bit_set_unchecked(&self, pos: usize) -> bool
pub fn is_bit_set_unchecked(&self, pos: usize) -> bool
Return whether the bit at the given position is set.
§Panics
If the position is larger than the length of the vector,
the function will either return unpredictable data, or panic.
Use is_bit_set to properly handle this case with an Option.
Sourcepub fn get_bits(&self, pos: usize, len: usize) -> Option<u64>
pub fn get_bits(&self, pos: usize, len: usize) -> Option<u64>
Return multiple bits at the given position.
The number of bits to return is given by len.
At most 64 bits can be returned.
If the position at the end of the query is larger than the length of the vector,
None is returned (even if the query partially overlaps with the vector).
If the length of the query is larger than 64, None is returned.
The first bit at pos is the most significant bit of the return value
limited to len bits.
Sourcepub fn get_bits_unchecked(&self, pos: usize, len: usize) -> u64
pub fn get_bits_unchecked(&self, pos: usize, len: usize) -> u64
Return multiple bits at the given position. The number of bits to return is given by len.
At most 64 bits can be returned.
This function is always inlined, because it gains a lot from loop optimization and can utilize the processor pre-fetcher better if it is.
§Errors
If the length of the query is larger than 64, unpredictable data will be returned.
Use get_bits to avoid this.
§Panics
If the position or interval is larger than the length of the vector, the function will either return any valid results padded with unpredictable data or panic.
Sourcepub fn unpack_element(&self, index: usize, n: usize) -> Option<u64>
pub fn unpack_element(&self, index: usize, n: usize) -> Option<u64>
Extract a packed element from a bit vector. The element is encoded in the bits at the given
index. The number of bits per encoded element is given by n.
This is a convenience method to access elements previously packed using the pack_sequence_* methods,
and is equivalent to calling get_bits(index * n, n).
It is thus safe to use this method with any index and any size n <= 64.
If the element is out of bounds, None is returned. The element is returned as a u64 value.
§Example
use vers_vecs::BitVec;
let sequence = [10, 100, 124, 45, 223];
let bv = BitVec::pack_sequence_u64(&sequence, 8);
assert_eq!(bv.unpack_element(0, 8), Some(10));
assert_eq!(bv.unpack_element(2, 8), Some(124));Sourcepub fn unpack_element_unchecked(&self, index: usize, n: usize) -> u64
pub fn unpack_element_unchecked(&self, index: usize, n: usize) -> u64
Extract a packed element from a bit vector. The element is encoded in the bits at the given
index. The number of bits per encoded element is given by n.
This is a convenience method to access elements previously packed using the pack_sequence_* methods,
and is equivalent to calling get_bits_unchecked(index * n, n).
It is thus safe to use this method with any index where index * n + n is in-bounds,
and any size n <= 64.
§Panics
If the element is out of bounds, the function will either return unpredictable data or panic.
Use unpack_element for a checked version of this function.
Sourcepub fn count_ones(&self) -> u64
pub fn count_ones(&self) -> u64
Return the number of ones in the bit vector. Since the bit vector doesn’t store additional
metadata, this value is calculated. Use RsVec for constant-time rank operations.
Sourcepub fn count_zeros(&self) -> u64
pub fn count_zeros(&self) -> u64
Return the number of zeros in the bit vector. Since the bit vector doesn’t store additional
metadata, this value is calculated. Use RsVec for constant-time rank operations.
This method calls count_ones.
Sourcepub fn mask_or<'s, 'b>(
&'s self,
mask: &'b BitVec,
) -> Result<BitMask<'s, 'b>, String>
pub fn mask_or<'s, 'b>( &'s self, mask: &'b BitVec, ) -> Result<BitMask<'s, 'b>, String>
Mask this bit vector with another bitvector using bitwise or. The mask is applied lazily whenever an operation on the resulting vector is performed.
§Errors
Returns an error if the length of the vector doesn’t match the mask length.
Sourcepub fn mask_and<'s, 'b>(
&'s self,
mask: &'b BitVec,
) -> Result<BitMask<'s, 'b>, String>
pub fn mask_and<'s, 'b>( &'s self, mask: &'b BitVec, ) -> Result<BitMask<'s, 'b>, String>
Mask this bit vector with another bitvector using bitwise and. The mask is applied lazily whenever an operation on the resulting vector is performed.
§Errors
Returns an error if the length of the vector doesn’t match the mask length.
Sourcepub fn mask_xor<'s, 'b>(
&'s self,
mask: &'b BitVec,
) -> Result<BitMask<'s, 'b>, String>
pub fn mask_xor<'s, 'b>( &'s self, mask: &'b BitVec, ) -> Result<BitMask<'s, 'b>, String>
Mask this bit vector with another bitvector using bitwise xor. The mask is applied lazily whenever an operation on the resulting vector is performed.
§Errors
Returns an error if the length of the vector doesn’t match the mask length.
Sourcepub fn mask_custom<'s, 'b, F>(
&'s self,
mask: &'b BitVec,
mask_op: F,
) -> Result<MaskedBitVec<'s, 'b, F>, String>
pub fn mask_custom<'s, 'b, F>( &'s self, mask: &'b BitVec, mask_op: F, ) -> Result<MaskedBitVec<'s, 'b, F>, String>
Mask this bit vector with another bitvector using a custom masking operation. The mask is applied lazily whenever an operation on the resulting vector is performed.
The masking operation takes two 64 bit values which contain blocks of 64 bits each. The last block of a bit vector might contain fewer bits, and will be padded with unpredictable data. Implementations may choose to modify those padding bits without repercussions. Implementations shouldn’t use operations like bit shift, because the bit order within the vector is unspecified.
§Errors
Returns an error if the length of the vector doesn’t match the mask length.
Sourcepub fn apply_mask_custom(
&mut self,
mask: &BitVec,
mask_op: fn(u64, u64) -> u64,
) -> Result<(), String>
pub fn apply_mask_custom( &mut self, mask: &BitVec, mask_op: fn(u64, u64) -> u64, ) -> Result<(), String>
Mask this bit vector with another bitvector using a custom masking operation.
The mask is applied immediately, unlike in mask_custom.
The masking operation takes two 64 bit values which contain blocks of 64 bits each. The last block of a bit vector might contain fewer bits, and will be padded with unpredictable data. Implementations may choose to modify those padding bits without repercussions. Implementations shouldn’t use operations like bit shift, because the bit order within the vector is unspecified.
§Errors
Returns an error if the length of the vector doesn’t match the mask length.
Sourcepub fn heap_size(&self) -> usize
pub fn heap_size(&self) -> usize
Returns the number of bytes on the heap for this vector. Does not include allocated memory that isn’t used.
Sourcepub fn split_at(self, at: usize) -> Result<(Self, Self), Self>
pub fn split_at(self, at: usize) -> Result<(Self, Self), Self>
Split the vector in two at the specified index. The left half contains bits 0..at and the
right half the remaining bits at... If the split index is larger than the length of the
vector, the vector is returned unmodified in an Err variant.
§Errors
If the index is out of bounds, the function will return an error containing the original vector.
See also: split_at_unchecked
Sourcepub fn split_at_unchecked(self, at: usize) -> (Self, Self)
pub fn split_at_unchecked(self, at: usize) -> (Self, Self)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for BitVec
impl<'de> Deserialize<'de> for BitVec
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'t> Extend<&'t BitVec> for BitVec
impl<'t> Extend<&'t BitVec> for BitVec
Source§fn extend<T: IntoIterator<Item = &'t BitVec>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'t BitVec>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<BitVec> for BitVec
impl Extend<BitVec> for BitVec
Source§fn extend<T: IntoIterator<Item = BitVec>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = BitVec>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl From<&[u64]> for BitVec
Create a new bit vector from a slice of u64 values.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The function will append the bits of each element to the bit vector in the order they are
given in the slice (i.e. the first element takes bits 0..64 of the vector).
impl From<&[u64]> for BitVec
Create a new bit vector from a slice of u64 values.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The function will append the bits of each element to the bit vector in the order they are
given in the slice (i.e. the first element takes bits 0..64 of the vector).
Source§impl<'a> From<&'a BitVec> for SparseRSVec
impl<'a> From<&'a BitVec> for SparseRSVec
Source§impl From<BitVec> for SparseRSVec
impl From<BitVec> for SparseRSVec
Source§impl From<Vec<u64>> for BitVec
Create a new bit vector from a slice of u64 values.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The function will append the bits of each element to the bit vector in the order they are
given in the slice (i.e. the first element takes bits 0..64 of the vector).
impl From<Vec<u64>> for BitVec
Create a new bit vector from a slice of u64 values.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The function will append the bits of each element to the bit vector in the order they are
given in the slice (i.e. the first element takes bits 0..64 of the vector).
Source§impl FromIterator<u64> for BitVec
Create a new bit vector from u64 values.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The function will append the bits of each element to the bit vector in the order they are
given in the iterator (i.e. the first element takes bits 0..64 of the vector).
impl FromIterator<u64> for BitVec
Create a new bit vector from u64 values.
The bits are appended in little-endian order (i.e. the least significant bit is appended first).
The function will append the bits of each element to the bit vector in the order they are
given in the iterator (i.e. the first element takes bits 0..64 of the vector).