Struct ethcore_util::nibbleslice::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
extern crate ethcore_util; use ethcore_util::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); }
Methods
impl<'a, 'view> NibbleSlice<'a> where 'a: 'view
[src]
fn new(data: &'a [u8]) -> Self
Create a new nibble slice with the given byte-slice.
fn new_offset(data: &'a [u8], offset: usize) -> Self
Create a new nibble slice with the given byte-slice with a nibble offset.
fn new_composed(a: &'a NibbleSlice, b: &'a NibbleSlice) -> Self
Create a composed nibble slice; one followed by the other.
fn iter(&'a self) -> NibbleSliceIterator<'a>
Get an iterator for the series of nibbles.
fn from_encoded(data: &'a [u8]) -> (NibbleSlice, bool)
Create a new nibble slice from the given HPE encoded data (e.g. output of encoded()
).
fn is_empty(&self) -> bool
Is this an empty slice?
fn len(&self) -> usize
Get the length (in nibbles, naturally) of this slice.
fn at(&self, i: usize) -> u8
Get the nibble at position i
.
fn mid(&'view self, i: usize) -> NibbleSlice<'a>
Return object which represents a view on to this slice (further) offset by i
nibbles.
fn starts_with(&self, them: &Self) -> bool
Do we start with the same nibbles as the whole of them
?
fn common_prefix(&self, them: &Self) -> usize
How many of the same nibbles at the beginning do we match with them
?
fn encoded(&self, is_leaf: bool) -> ElasticArray36<u8>
Encode while nibble slice in prefixed hex notation, noting whether it is_leaf
.
fn encoded_leftmost(&self, n: usize, is_leaf: bool) -> ElasticArray36<u8>
Encode only the leftmost n
bytes of the nibble slice in prefixed hex notation,
noting whether it is_leaf
.
Trait Implementations
impl<'a> Copy for NibbleSlice<'a>
[src]
impl<'a> Clone for NibbleSlice<'a>
[src]
fn clone(&self) -> NibbleSlice<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<'a> Eq for NibbleSlice<'a>
[src]
impl<'a> Ord for NibbleSlice<'a>
[src]
fn cmp(&self, __arg_0: &NibbleSlice<'a>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<'a> PartialEq for NibbleSlice<'a>
[src]
fn eq(&self, them: &Self) -> 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
This method tests for !=
.
impl<'a> PartialOrd for NibbleSlice<'a>
[src]
fn partial_cmp(&self, them: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more