Struct merkle_log::TreeID [−][src]
Unique identifiers for binary tree nodes. Reproduced from flat-tree.
Implementations
impl TreeID
[src]
pub const fn new(depth: u8, index: u64) -> Self
[src]
Returns a node’s unique id within the tree, given its depth and index.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::new(0, 0), 0usize); assert_eq!(TreeID::new(0, 1), 2usize); assert_eq!(TreeID::new(0, 2), 4usize); assert_eq!(TreeID::new(1, 2), 9usize); assert_eq!(TreeID::new(1, 3), 13usize); assert_eq!(TreeID::new(2, 1), 11usize); assert_eq!(TreeID::new(2, 2), 19usize); assert_eq!(TreeID::new(3, 0), 7usize); assert_eq!(TreeID::new(3, 1), 23usize);
pub const fn index(&self) -> u64
[src]
Returns a node’s index among nodes of the same depth.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::from(0).index(), 0); assert_eq!(TreeID::from(1).index(), 0); assert_eq!(TreeID::from(2).index(), 1); assert_eq!(TreeID::from(3).index(), 0); assert_eq!(TreeID::from(4).index(), 2);
pub const fn depth(&self) -> u8
[src]
Returns a node’s depth in the tree.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::from(0).depth(), 0); assert_eq!(TreeID::from(1).depth(), 1); assert_eq!(TreeID::from(2).depth(), 0); assert_eq!(TreeID::from(3).depth(), 2); assert_eq!(TreeID::from(4).depth(), 0);
pub const fn parent(&self) -> Self
[src]
Returns the parent id of a node.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::from(0).parent(), 1usize); assert_eq!(TreeID::from(1).parent(), 3usize); assert_eq!(TreeID::from(2).parent(), 1usize); assert_eq!(TreeID::from(3).parent(), 7usize); assert_eq!(TreeID::from(4).parent(), 5usize); assert_eq!(TreeID::from(5).parent(), 3usize); assert_eq!(TreeID::from(6).parent(), 5usize); assert_eq!(TreeID::from(7).parent(), 15usize); assert_eq!(TreeID::from(8).parent(), 9usize);
pub const fn sibling(&self) -> Self
[src]
Returns the sibling id of a node.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::from(0).sibling(), 2usize); assert_eq!(TreeID::from(2).sibling(), 0usize); assert_eq!(TreeID::from(1).sibling(), 5usize); assert_eq!(TreeID::from(5).sibling(), 1usize);
pub const fn uncle(&self) -> Self
[src]
Given a node, returns its parent’s sibling’s id.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::from(0).uncle(), 5usize); assert_eq!(TreeID::from(2).uncle(), 5usize); assert_eq!(TreeID::from(1).uncle(), 11usize); assert_eq!(TreeID::from(5).uncle(), 11usize); assert_eq!(TreeID::from(9).uncle(), 3usize);
pub const fn left(&self) -> Option<Self>
[src]
Returns the id of the node’s left child.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::from(0).left(), None); assert_eq!(TreeID::from(1).left(), Some(TreeID::from(0))); assert_eq!(TreeID::from(3).left(), Some(TreeID::from(1)));
pub const fn right(&self) -> Option<Self>
[src]
Returns the id of the node’s right child.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::from(0).right(), None); assert_eq!(TreeID::from(1).right(), Some(TreeID::from(2))); assert_eq!(TreeID::from(3).right(), Some(TreeID::from(5)));
pub const fn span(&self) -> (Self, Self)
[src]
Returns the left- and right-most node ids in the tree the node spans.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::from(0).span(), (TreeID::from(0), TreeID::from(0))); assert_eq!(TreeID::from(1).span(), (TreeID::from(0), TreeID::from(2))); assert_eq!(TreeID::from(3).span(), (TreeID::from(0), TreeID::from(6))); assert_eq!(TreeID::from(23).span(), (TreeID::from(16), TreeID::from(30))); assert_eq!(TreeID::from(27).span(), (TreeID::from(24), TreeID::from(30)));
pub fn spans(&self, other: &Self) -> bool
[src]
Determines if the id’s tree spans (i.e. contains) another id.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::from(0).spans(&TreeID::from(0)), true); assert_eq!(TreeID::from(0).spans(&TreeID::from(1)), false); assert_eq!(TreeID::from(1).spans(&TreeID::from(0)), true); assert_eq!(TreeID::from(1).spans(&TreeID::from(1)), true); assert_eq!(TreeID::from(1).spans(&TreeID::from(2)), true); assert_eq!(TreeID::from(3).spans(&TreeID::from(1)), true); assert_eq!(TreeID::from(3).spans(&TreeID::from(5)), true); assert_eq!(TreeID::from(3).spans(&TreeID::from(7)), false);
pub fn subroots(size: u64) -> Vec<Self>
[src]
The root ids of the highest complete subtrees within a log of a given
size
.
Examples
use merkle_log::TreeID; assert_eq!(TreeID::subroots(0), Vec::<TreeID>::new()); assert_eq!(TreeID::subroots(1), &[TreeID::from(0)]); assert_eq!(TreeID::subroots(2), &[TreeID::from(1)]); assert_eq!(TreeID::subroots(3), &[TreeID::from(1), TreeID::from(4)]); assert_eq!(TreeID::subroots(4), &[TreeID::from(3)]); assert_eq!(TreeID::subroots(5), &[TreeID::from(3), TreeID::from(8)]); assert_eq!(TreeID::subroots(6), &[TreeID::from(3), TreeID::from(9)]); assert_eq!(TreeID::subroots(7), &[TreeID::from(3), TreeID::from(9), TreeID::from(12)]); assert_eq!(TreeID::subroots(8), &[TreeID::from(7)]); assert_eq!(TreeID::subroots(9), &[TreeID::from(7), TreeID::from(16)]); assert_eq!(TreeID::subroots(10), &[TreeID::from(7), TreeID::from(17)]);
Trait Implementations
impl Clone for TreeID
[src]
impl Copy for TreeID
[src]
impl Debug for TreeID
[src]
impl Eq for TreeID
[src]
impl From<u64> for TreeID
[src]
impl Hash for TreeID
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for TreeID
[src]
fn cmp(&self, other: &TreeID) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<TreeID> for TreeID
[src]
impl PartialEq<u16> for TreeID
[src]
impl PartialEq<u32> for TreeID
[src]
impl PartialEq<u64> for TreeID
[src]
impl PartialEq<u8> for TreeID
[src]
impl PartialEq<usize> for TreeID
[src]
impl PartialOrd<TreeID> for TreeID
[src]
fn partial_cmp(&self, other: &TreeID) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for TreeID
[src]
impl StructuralPartialEq for TreeID
[src]
Auto Trait Implementations
impl RefUnwindSafe for TreeID
impl Send for TreeID
impl Sync for TreeID
impl Unpin for TreeID
impl UnwindSafe for TreeID
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,