Struct ex3_merkle::PartialTree

source ·
pub struct PartialTree<T: Hasher> { /* private fields */ }
Expand description

Partial tree represents a part of the original tree that is enough to calculate the root. Used in to extract the root in a merkle proof, to apply diff to a tree or to merge multiple trees into one.

It is a rare case when you need to use this struct on it’s own. It’s mostly used inside MerkleTree and MerkleProof

Implementations§

source§

impl<T: Hasher> PartialTree<T>

source

pub fn new() -> Self

Takes leaves (item hashes) as an argument and build a Merkle Tree from them. Since it’s a partial tree, hashes must be accompanied by their index in the original tree.

source

pub fn from_leaves(leaves: &[T::Hash]) -> Result<Self, Error>

This is a helper function to build a full tree from a full set of leaves without any helper indices

source

pub fn build( partial_layers: Vec<Vec<(usize, T::Hash)>>, depth: usize ) -> Result<Self, Error>

source

pub fn depth(&self) -> usize

Returns how many layers there is between leaves and the root

source

pub fn root(&self) -> Option<&T::Hash>

Return the root of the tree

source

pub fn contains(&self, layer_index: usize, node_index: usize) -> bool

source

pub fn merge_unverified(&mut self, other: Self)

Consumes other partial tree into itself, replacing any conflicting nodes with nodes from other in the process. Doesn’t rehash the nodes, so the integrity of the result is not verified. It gives an advantage in speed, but should be used only if the integrity of the tree can’t be broken, for example, it is used in the .commit method of the MerkleTree, since both partial trees are essentially constructed in place and there’s no need to verify integrity of the result.

source

pub fn layer_nodes(&self) -> Vec<Vec<T::Hash>>

source

pub fn layers(&self) -> &[Vec<(usize, T::Hash)>]

Returns partial tree layers

source

pub fn clear(&mut self)

Clears all elements in the ree

Trait Implementations§

source§

impl<T: Clone + Hasher> Clone for PartialTree<T>where T::Hash: Clone,

source§

fn clone(&self) -> PartialTree<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Hasher> Default for PartialTree<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for PartialTree<T>where <T as Hasher>::Hash: RefUnwindSafe,

§

impl<T> Send for PartialTree<T>where <T as Hasher>::Hash: Send,

§

impl<T> Sync for PartialTree<T>where <T as Hasher>::Hash: Sync,

§

impl<T> Unpin for PartialTree<T>where <T as Hasher>::Hash: Unpin,

§

impl<T> UnwindSafe for PartialTree<T>where <T as Hasher>::Hash: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.