Struct rs_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
sourceimpl<T: Hasher> PartialTree<T>
impl<T: Hasher> PartialTree<T>
sourcepub fn new() -> Self
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.
sourcepub fn from_leaves(leaves: &[T::Hash]) -> Result<Self, Error>
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
pub fn build(
partial_layers: Vec<Vec<(usize, T::Hash)>>,
depth: usize
) -> Result<Self, Error>
pub fn contains(&self, layer_index: usize, node_index: usize) -> bool
sourcepub fn merge_unverified(&mut self, other: Self)
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.
pub fn layer_nodes(&self) -> Vec<Vec<T::Hash>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Trait Implementations
sourceimpl<T: Clone + Hasher> Clone for PartialTree<T> where
T::Hash: Clone,
impl<T: Clone + Hasher> Clone for PartialTree<T> where
T::Hash: Clone,
sourcefn clone(&self) -> PartialTree<T>
fn clone(&self) -> PartialTree<T>
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
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more