pub struct NibbleVec<A>{ /* private fields */ }
Expand description
A data-structure for storing a sequence of 4-bit values.
Values are stored in a Vec<u8>
, with two values per byte.
Values at even indices are stored in the most-significant half of their byte, while values at odd indices are stored in the least-significant half.
Imagine a vector of MSB first bytes, and you’ll be right.
n = [_ _ | _ _ | _ _]
Implementations§
Source§impl<A> NibbleVec<A>
impl<A> NibbleVec<A>
Sourcepub fn from_byte_vec(vec: Vec<u8>) -> NibbleVec<A>
pub fn from_byte_vec(vec: Vec<u8>) -> NibbleVec<A>
Create a nibble vector from a vector of bytes.
Each byte is split into two 4-bit entries (MSB, LSB).
Sourcepub fn into_bytes(self) -> Vec<u8>
pub fn into_bytes(self) -> Vec<u8>
Converts a nibble vector into a byte vector.
This consumes the nibble vector, so we do not need to copy its contents.
Sourcepub fn get(&self, idx: usize) -> u8
pub fn get(&self, idx: usize) -> u8
Fetch a single entry from the vector.
Guaranteed to be a value in the interval [0, 15].
Panics if idx >= self.len()
.
Sourcepub fn push(&mut self, val: u8)
pub fn push(&mut self, val: u8)
Add a single nibble to the vector.
Only the 4 least-significant bits of the value are used.
Trait Implementations§
Source§impl<A> PartialEq<[u8]> for NibbleVec<A>
impl<A> PartialEq<[u8]> for NibbleVec<A>
Compare a NibbleVec
and a slice of bytes element-by-element.
Bytes are not interpreted as two NibbleVec
entries.