Struct miden_core::crypto::merkle::MerklePathSet
source · pub struct MerklePathSet { /* private fields */ }
Expand description
A set of Merkle paths.
Implementations§
source§impl MerklePathSet
impl MerklePathSet
sourcepub fn new(depth: u8) -> MerklePathSet
pub fn new(depth: u8) -> MerklePathSet
Returns an empty MerklePathSet.
sourcepub fn with_paths<I>(self, paths: I) -> Result<MerklePathSet, MerkleError>where
I: IntoIterator<Item = (u64, [BaseElement; 4], MerklePath)>,
pub fn with_paths<I>(self, paths: I) -> Result<MerklePathSet, MerkleError>where I: IntoIterator<Item = (u64, [BaseElement; 4], MerklePath)>,
Appends the provided paths iterator into the set.
Analogous to [Self::add_path]
.
sourcepub const fn root(&self) -> [BaseElement; 4]
pub const fn root(&self) -> [BaseElement; 4]
Returns the root to which all paths in this set resolve.
sourcepub const fn depth(&self) -> u8
pub const fn depth(&self) -> u8
Returns the depth of the Merkle tree implied by the paths stored in this set.
Merkle tree of depth 1 has two leaves, depth 2 has four leaves etc.
sourcepub fn get_node(
&self,
index: NodeIndex
) -> Result<[BaseElement; 4], MerkleError>
pub fn get_node( &self, index: NodeIndex ) -> Result<[BaseElement; 4], MerkleError>
Returns a node at the specified index.
Errors
Returns an error if:
- The specified index is not valid for the depth of structure.
- Requested node does not exist in the set.
sourcepub fn get_leaf(&self, index: u64) -> Result<[BaseElement; 4], MerkleError>
pub fn get_leaf(&self, index: u64) -> Result<[BaseElement; 4], MerkleError>
Returns a leaf at the specified index.
Errors
- The specified index is not valid for the depth of the structure.
- Leaf with the requested path does not exist in the set.
sourcepub fn get_path(&self, index: NodeIndex) -> Result<MerklePath, MerkleError>
pub fn get_path(&self, index: NodeIndex) -> Result<MerklePath, MerkleError>
Returns a Merkle path to the node at the specified index. The node itself is not included in the path.
Errors
Returns an error if:
- The specified index is not valid for the depth of structure.
- Node of the requested path does not exist in the set.
sourcepub fn to_paths(&self) -> Vec<(u64, ValuePath), Global>
pub fn to_paths(&self) -> Vec<(u64, ValuePath), Global>
Returns all paths in this path set together with their indexes.
sourcepub fn add_path(
&mut self,
index_value: u64,
value: [BaseElement; 4],
path: MerklePath
) -> Result<(), MerkleError>
pub fn add_path( &mut self, index_value: u64, value: [BaseElement; 4], path: MerklePath ) -> Result<(), MerkleError>
Adds the specified Merkle path to this MerklePathSet. The index
and value
parameters
specify the leaf node at which the path starts.
Errors
Returns an error if:
- The specified index is is not valid in the context of this Merkle path set (i.e., the index implies a greater depth than is specified for this set).
- The specified path is not consistent with other paths in the set (i.e., resolves to a different root).
sourcepub fn update_leaf(
&mut self,
base_index_value: u64,
value: [BaseElement; 4]
) -> Result<(), MerkleError>
pub fn update_leaf( &mut self, base_index_value: u64, value: [BaseElement; 4] ) -> Result<(), MerkleError>
Replaces the leaf at the specified index with the provided value.
Errors
Returns an error if:
- Requested node does not exist in the set.
Trait Implementations§
source§impl Clone for MerklePathSet
impl Clone for MerklePathSet
source§fn clone(&self) -> MerklePathSet
fn clone(&self) -> MerklePathSet
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MerklePathSet
impl Debug for MerklePathSet
source§impl PartialEq<MerklePathSet> for MerklePathSet
impl PartialEq<MerklePathSet> for MerklePathSet
source§fn eq(&self, other: &MerklePathSet) -> bool
fn eq(&self, other: &MerklePathSet) -> bool
self
and other
values to be equal, and is used
by ==
.