pub struct BalancedHashedMerkleTree<'a, const NUM_LEAVES_LOG_2: u32>{ /* private fields */ }
Expand description
Merkle Tree variant that has hash-sized leaves and is fully balanced according to configured generic parameter.
This Merkle Tree implementation is best suited for use cases when proofs for all (or most) of the elements need to be generated and the whole tree easily fits into memory. It can also be constructed and proofs can be generated efficiently without heap allocations.
With all parameters of the tree known statically, it results in the most efficient version of the code being generated for a given set of parameters.
NUM_LEAVES_LOG_2
is base-2 logarithm of the number of leaves in a tree.
Implementations§
Source§impl<'a, const NUM_LEAVES_LOG_2: u32> BalancedHashedMerkleTree<'a, NUM_LEAVES_LOG_2>
impl<'a, const NUM_LEAVES_LOG_2: u32> BalancedHashedMerkleTree<'a, NUM_LEAVES_LOG_2>
Sourcepub fn new(leaf_hashes: &'a [[u8; 32]; { _ }]) -> Self
pub fn new(leaf_hashes: &'a [[u8; 32]; { _ }]) -> Self
Create a new tree from a fixed set of elements.
The data structure is statically allocated and might be too large to fit on the stack!
If that is the case, use new_boxed()
method.
Sourcepub fn new_in<'b>(
instance: &'b mut MaybeUninit<Self>,
leaf_hashes: &'a [[u8; 32]; { _ }],
) -> &'b mut Self
pub fn new_in<'b>( instance: &'b mut MaybeUninit<Self>, leaf_hashes: &'a [[u8; 32]; { _ }], ) -> &'b mut Self
Like Self::new()
, but used pre-allocated memory for instantiation
Sourcepub fn new_boxed(leaf_hashes: &'a [[u8; 32]; { _ }]) -> Box<Self>
pub fn new_boxed(leaf_hashes: &'a [[u8; 32]; { _ }]) -> Box<Self>
Like Self::new()
, but creates heap-allocated instance, avoiding excessive stack usage
for large trees
Sourcepub fn root(&self) -> [u8; 32]
pub fn root(&self) -> [u8; 32]
Get the root of Merkle Tree.
In case a tree contains a single leaf hash, that leaf hash is returned.
Sourcepub fn all_proofs(
&self,
) -> impl ExactSizeIterator<Item = [u8; { _ }]> + TrustedLen
pub fn all_proofs( &self, ) -> impl ExactSizeIterator<Item = [u8; { _ }]> + TrustedLen
Iterator over proofs in the same order as provided leaf hashes