Struct BitChunks
pub struct BitChunks<'a> {
buffer: &'a [u8],
bit_offset: usize,
chunk_len: usize,
remainder_len: usize,
}Expand description
Iterates over an arbitrarily aligned byte buffer 64 bits at a time
Self::iter yields iterator of u64, and a remainder. The first byte in the buffer
will be the least significant byte in output u64
Fields§
§buffer: &'a [u8]§bit_offset: usize§chunk_len: usize§remainder_len: usizeImplementations§
§impl<'a> BitChunks<'a>
impl<'a> BitChunks<'a>
pub const fn remainder_len(&self) -> usize
pub const fn remainder_len(&self) -> usize
Returns the number of remaining bits, guaranteed to be between 0 and 63 (inclusive)
pub fn remainder_bits(&self) -> u64
pub fn remainder_bits(&self) -> u64
Returns the bitmask of remaining bits
pub fn num_u64s(&self) -> usize
pub fn num_u64s(&self) -> usize
Return the number of u64 that are needed to represent all bits
(including remainder).
This is equal to chunk_len + 1 if there is a remainder,
otherwise it is equal to chunk_len.
pub fn num_bytes(&self) -> usize
pub fn num_bytes(&self) -> usize
Return the number of bytes that are needed to represent all bits (including remainder).
pub fn chunk(&self, index: usize) -> u64
pub fn chunk(&self, index: usize) -> u64
Returns the indexth complete chunk of 64 bits, the value
Self::iter yields at that position
§Panics
Panics if index >= self.chunk_len()
§Example
let buffer = Buffer::from((0..17_u8).collect::<Vec<_>>());
// Start at bit 8, so chunk 1 holds bytes 9 through 16
let chunks = buffer.bit_chunks(8, 128);
assert_eq!(chunks.chunk_len(), 2);
assert_eq!(chunks.chunk(1), 0x100f0e0d0c0b0a09);
assert_eq!(chunks.iter().nth(1), Some(chunks.chunk(1)));pub const fn iter(&self) -> BitChunkIterator<'a> ⓘ
pub const fn iter(&self) -> BitChunkIterator<'a> ⓘ
Returns an iterator over chunks of 64 bits represented as an u64
pub fn iter_padded(&self) -> impl Iterator<Item = u64> + 'a
pub fn iter_padded(&self) -> impl Iterator<Item = u64> + 'a
Returns an iterator over chunks of 64 bits, with the remaining bits zero padded to 64-bits