Struct radix_trie::NibbleVec [−][src]
pub struct NibbleVec { /* fields omitted */ }
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 = [_ _ | _ _ | _ _]
Methods
impl NibbleVec
[src]
impl NibbleVec
pub fn new() -> NibbleVec
[src]
pub fn new() -> NibbleVec
Create an empty nibble vector.
pub fn from_byte_vec(vec: Vec<u8>) -> NibbleVec
[src]
pub fn from_byte_vec(vec: Vec<u8>) -> NibbleVec
Create a nibble vector from a vector of bytes.
Each byte is split into two 4-bit entries (MSB, LSB).
pub fn as_bytes(&self) -> &[u8]
[src]
pub fn as_bytes(&self) -> &[u8]
Returns a byte slice of the nibble vector's contents.
pub fn into_bytes(self) -> Vec<u8>
[src]
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.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Get the number of elements stored in the vector.
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns true
if the nibble vector has a length of 0.
pub fn get(&self, idx: usize) -> u8
[src]
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()
.
pub fn push(&mut self, val: u8)
[src]
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.
pub fn split(&mut self, idx: usize) -> NibbleVec
[src]
pub fn split(&mut self, idx: usize) -> NibbleVec
Split the vector into two parts.
All elements at or following the given index are returned in a new NibbleVec
,
with exactly idx
elements remaining in this vector.
Panics if idx > self.len()
.
pub fn join(self, other: &NibbleVec) -> NibbleVec
[src]
pub fn join(self, other: &NibbleVec) -> NibbleVec
Append another nibble vector whilst consuming this vector.
Trait Implementations
impl<'a> Into<Vec<u8>> for &'a NibbleVec
[src]
impl<'a> Into<Vec<u8>> for &'a NibbleVec
impl Into<Vec<u8>> for NibbleVec
[src]
impl Into<Vec<u8>> for NibbleVec
impl Clone for NibbleVec
[src]
impl Clone for NibbleVec
fn clone(&self) -> NibbleVec
[src]
fn clone(&self) -> NibbleVec
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Default for NibbleVec
[src]
impl Default for NibbleVec
impl Debug for NibbleVec
[src]
impl Debug for NibbleVec
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl Eq for NibbleVec
[src]
impl Eq for NibbleVec
impl PartialEq<[u8]> for NibbleVec
[src]
impl PartialEq<[u8]> for NibbleVec
Compare a NibbleVec
and a slice of bytes element-by-element.
Bytes are not interpreted as two NibbleVec
entries.
fn eq(&self, other: &[u8]) -> bool
[src]
fn eq(&self, other: &[u8]) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl PartialEq<NibbleVec> for NibbleVec
[src]
impl PartialEq<NibbleVec> for NibbleVec
fn eq(&self, other: &NibbleVec) -> bool
[src]
fn eq(&self, other: &NibbleVec) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> From<&'a [u8]> for NibbleVec
[src]
impl<'a> From<&'a [u8]> for NibbleVec
impl From<Vec<u8>> for NibbleVec
[src]
impl From<Vec<u8>> for NibbleVec