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>
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>>
Trait Implementations§
source§impl<T: Clone + Hasher> Clone for PartialTree<T>
impl<T: Clone + Hasher> Clone for PartialTree<T>
source§fn clone(&self) -> PartialTree<T>
fn clone(&self) -> PartialTree<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<T> Freeze for PartialTree<T>
impl<T> RefUnwindSafe for PartialTree<T>
impl<T> Send for PartialTree<T>
impl<T> Sync for PartialTree<T>
impl<T> Unpin for PartialTree<T>
impl<T> UnwindSafe for PartialTree<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)