Struct trie_db::NibbleSlice
source · [−]pub struct NibbleSlice<'a> { /* private fields */ }
Expand description
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
sourceimpl<'a> NibbleSlice<'a>
impl<'a> NibbleSlice<'a>
sourcepub fn new_offset(data: &'a [u8], offset: usize) -> Self
pub fn new_offset(data: &'a [u8], offset: usize) -> Self
Create a new nibble slice with the given byte-slice with a nibble offset.
sourcepub fn from_stored(i: &NodeKey) -> NibbleSlice<'_>
pub fn from_stored(i: &NodeKey) -> NibbleSlice<'_>
Get nibble slice from a NodeKey
.
sourcepub fn to_stored(&self) -> NodeKey
pub fn to_stored(&self) -> NodeKey
Helper function to create a owned NodeKey
from this NibbleSlice
.
sourcepub fn to_stored_range(&self, nb: usize) -> NodeKey
pub fn to_stored_range(&self, nb: usize) -> NodeKey
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).
sourcepub fn mid(&self, i: usize) -> NibbleSlice<'a>
pub fn mid(&self, i: usize) -> NibbleSlice<'a>
Return object which represents a view on to this slice (further) offset by i
nibbles.
sourcepub fn back(&self, i: usize) -> NibbleSlice<'a>
pub fn back(&self, i: usize) -> NibbleSlice<'a>
Move back to a previously valid fix offset position.
sourcepub fn starts_with(&self, them: &Self) -> bool
pub fn starts_with(&self, them: &Self) -> bool
Do we start with the same nibbles as the whole of them
?
sourcepub fn common_prefix(&self, them: &Self) -> usize
pub fn common_prefix(&self, them: &Self) -> usize
How many of the same nibbles at the beginning do we match with them
?
sourcepub fn right(&'a self) -> Partial<'_>
pub fn right(&'a self) -> Partial<'_>
Return Partial
representation of this slice:
first encoded byte and following slice.
sourcepub fn right_iter(&'a self) -> impl Iterator<Item = u8> + 'a
pub fn right_iter(&'a self) -> impl Iterator<Item = u8> + 'a
Return an iterator over Partial
bytes representation.
sourcepub fn right_range_iter(&'a self, to: usize) -> impl Iterator<Item = u8> + 'a
pub fn right_range_iter(&'a self, to: usize) -> impl Iterator<Item = u8> + 'a
Return Partial
bytes iterator over a range of byte..
Warning can be slow when unaligned (similar to to_stored_range
).
Trait Implementations
sourceimpl<'a> Clone for NibbleSlice<'a>
impl<'a> Clone for NibbleSlice<'a>
sourcefn clone(&self) -> NibbleSlice<'a>
fn clone(&self) -> NibbleSlice<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> Debug for NibbleSlice<'a>
impl<'a> Debug for NibbleSlice<'a>
sourceimpl<'a> From<NibbleSlice<'a>> for NibbleVec
impl<'a> From<NibbleSlice<'a>> for NibbleVec
sourcefn from(s: NibbleSlice<'a>) -> Self
fn from(s: NibbleSlice<'a>) -> Self
Performs the conversion.
sourceimpl<'a> Ord for NibbleSlice<'a>
impl<'a> Ord for NibbleSlice<'a>
sourceimpl<'a> PartialEq<NibbleSlice<'a>> for NibbleSlice<'a>
impl<'a> PartialEq<NibbleSlice<'a>> for NibbleSlice<'a>
sourceimpl<'a> PartialOrd<NibbleSlice<'a>> for NibbleSlice<'a>
impl<'a> PartialOrd<NibbleSlice<'a>> for NibbleSlice<'a>
sourcefn partial_cmp(&self, them: &Self) -> Option<Ordering>
fn partial_cmp(&self, them: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<'a> Copy for NibbleSlice<'a>
impl<'a> Eq for NibbleSlice<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for NibbleSlice<'a>
impl<'a> Send for NibbleSlice<'a>
impl<'a> Sync for NibbleSlice<'a>
impl<'a> Unpin for NibbleSlice<'a>
impl<'a> UnwindSafe for NibbleSlice<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more