pub struct MerkleTree { /* private fields */ }
Implementations§
source§impl MerkleTree
impl MerkleTree
pub fn new() -> Self
sourcepub fn from_set<I, D>(set: I) -> Self
pub fn from_set<I, D>(set: I) -> Self
Build a sparse Merkle tree from a set of key-value pairs. This is
equivalent to creating an empty sparse Merkle tree and sequentially
calling update for each key-value pair. This constructor
is more performant than calling individual sequential updates and is the
preferred approach when the key-values are known upfront. Leaves can be
appended to the returned tree using update
to further accumulate leaf
data.
sourcepub fn root_from_set<I, D>(set: I) -> Bytes32
pub fn root_from_set<I, D>(set: I) -> Bytes32
Calculate the sparse Merkle root from a set of key-value pairs. This is
similar to constructing a new tree from a set of key-value pairs using
from_set, except this method returns only the root; it
does not write to storage nor return a sparse Merkle tree instance. It
is equivalent to calling from_set(..)
, followed by root()
, but does
not incur the overhead of storage writes. This can be helpful when we
know all the key-values in the set upfront and we will not need to
update the set in the future.
sourcepub fn nodes_from_set<I, D>(set: I) -> (Bytes32, Vec<(Bytes32, Primitive)>)
pub fn nodes_from_set<I, D>(set: I) -> (Bytes32, Vec<(Bytes32, Primitive)>)
Calculate the sparse Merkle root as well as all nodes in the Merkle tree from a set of key-value pairs. This is similar to constructing a new tree from a set of key-value pairs using from_set, except this method returns only the root and the list of leaves and nodes in the tree; it does not return a sparse Merkle tree instance. This can be helpful when we know all the key-values in the set upfront and we need to defer storage writes, such as expensive database inserts, for batch operations later in the process.