Struct trie_db::NibbleSlice [−][src]
pub struct NibbleSlice<'a> { /* fields omitted */ }Nibble-orientated view onto byte-slice, allowing nibble-precision offsets.
This is an immutable struct. No operations actually change it.
Example
use patricia_trie::nibbleslice::NibbleSlice;
fn main() {
let d1 = &[0x01u8, 0x23, 0x45];
let d2 = &[0x34u8, 0x50, 0x12];
let d3 = &[0x00u8, 0x12];
let n1 = NibbleSlice::new(d1); // 0,1,2,3,4,5
let n2 = NibbleSlice::new(d2); // 3,4,5,0,1,2
let n3 = NibbleSlice::new_offset(d3, 1); // 0,1,2
assert!(n1 > n3); // 0,1,2,... > 0,1,2
assert!(n1 < n2); // 0,... < 3,...
assert!(n2.mid(3) == n3); // 0,1,2 == 0,1,2
assert!(n1.starts_with(&n3));
assert_eq!(n1.common_prefix(&n3), 3);
assert_eq!(n2.mid(3).common_prefix(&n1), 3);
}
Implementations
impl<'a> NibbleSlice<'a>[src]
impl<'a> NibbleSlice<'a>[src]pub fn new(data: &'a [u8]) -> Self[src]
Create a new nibble slice with the given byte-slice.
pub fn new_offset(data: &'a [u8], offset: usize) -> Self[src]
Create a new nibble slice with the given byte-slice with a nibble offset.
pub fn iter(&'a self) -> NibbleSliceIterator<'a>[src]
Get an iterator for the series of nibbles.
pub fn from_stored(i: &NodeKey) -> NibbleSlice<'_>[src]
Get nibble slice from a NodeKey.
pub fn to_stored(&self) -> NodeKey[src]
Helper function to create a owned NodeKey from this NibbleSlice.
pub fn to_stored_range(&self, nb: usize) -> NodeKey[src]
Helper function to create a owned NodeKey from this NibbleSlice,
and for a given number of nibble.
Warning this method can be slow (number of nibble does not align the
original padding).
pub fn is_empty(&self) -> bool[src]
Return true if the slice contains no nibbles.
pub fn len(&self) -> usize[src]
Get the length (in nibbles, naturally) of this slice.
pub fn at(&self, i: usize) -> u8[src]
Get the nibble at position i.
pub fn mid(&self, i: usize) -> NibbleSlice<'a>[src]
Return object which represents a view on to this slice (further) offset by i nibbles.
pub fn advance(&mut self, i: usize)[src]
Advance the view on the slice by i nibbles.
pub fn back(&self, i: usize) -> NibbleSlice<'a>[src]
Move back to a previously valid fix offset position.
pub fn starts_with(&self, them: &Self) -> bool[src]
Do we start with the same nibbles as the whole of them?
pub fn common_prefix(&self, them: &Self) -> usize[src]
How many of the same nibbles at the beginning do we match with them?
pub fn right(&'a self) -> Partial<'_>[src]
Return Partial representation of this slice:
first encoded byte and following slice.
pub fn right_iter(&'a self) -> impl Iterator<Item = u8> + 'a[src]
Return an iterator over Partial bytes representation.
pub fn right_range_iter(&'a self, to: usize) -> impl Iterator<Item = u8> + 'a[src]
Return Partial bytes iterator over a range of byte..
Warning can be slow when unaligned (similar to to_stored_range).
pub fn left(&'a self) -> Prefix<'_>[src]
Return left portion of NibbleSlice, if the slice
originates from a full key it will be the Prefix of the node.
pub fn left_owned(&'a self) -> (SmallVec<[u8; 36]>, Option<u8>)[src]
Owned version of a Prefix from a left method call.
Trait Implementations
impl<'a> Clone for NibbleSlice<'a>[src]
impl<'a> Clone for NibbleSlice<'a>[src]fn clone(&self) -> NibbleSlice<'a>[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl<'a> From<NibbleSlice<'a>> for NibbleVec[src]
impl<'a> From<NibbleSlice<'a>> for NibbleVec[src]fn from(s: NibbleSlice<'a>) -> Self[src]
impl<'a> Ord for NibbleSlice<'a>[src]
impl<'a> Ord for NibbleSlice<'a>[src]impl<'a> PartialEq<NibbleSlice<'a>> for NibbleSlice<'a>[src]
impl<'a> PartialEq<NibbleSlice<'a>> for NibbleSlice<'a>[src]impl<'a> PartialOrd<NibbleSlice<'a>> for NibbleSlice<'a>[src]
impl<'a> PartialOrd<NibbleSlice<'a>> for NibbleSlice<'a>[src]