add get_value() to SparseMerkleTree trait
This commit is contained in:
parent
2fac7f11d9
commit
3d9c82bbe5
3 changed files with 19 additions and 0 deletions
|
@ -249,6 +249,15 @@ impl SparseMerkleTree<SMT_DEPTH> for Smt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_value(&self, key: &RpoDigest) -> Word {
|
||||||
|
let leaf_pos = LeafIndex::<SMT_DEPTH>::from(*key).value();
|
||||||
|
|
||||||
|
self.leaves
|
||||||
|
.get(&leaf_pos)
|
||||||
|
.map(|leaf| leaf.get_value(key).unwrap_or_default())
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
fn get_leaf(&self, key: &RpoDigest) -> Self::Leaf {
|
fn get_leaf(&self, key: &RpoDigest) -> Self::Leaf {
|
||||||
let leaf_pos = LeafIndex::<SMT_DEPTH>::from(*key).value();
|
let leaf_pos = LeafIndex::<SMT_DEPTH>::from(*key).value();
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,9 @@ pub(crate) trait SparseMerkleTree<const DEPTH: u8> {
|
||||||
/// Inserts a leaf node, and returns the value at the key if already exists
|
/// Inserts a leaf node, and returns the value at the key if already exists
|
||||||
fn insert_value(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>;
|
fn insert_value(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>;
|
||||||
|
|
||||||
|
/// Returns the value at the specified key, without modifying the tree.
|
||||||
|
fn get_value(&self, key: &Self::Key) -> Self::Value;
|
||||||
|
|
||||||
/// Returns the leaf at the specified index.
|
/// Returns the leaf at the specified index.
|
||||||
fn get_leaf(&self, key: &Self::Key) -> Self::Leaf;
|
fn get_leaf(&self, key: &Self::Key) -> Self::Leaf;
|
||||||
|
|
||||||
|
|
|
@ -288,6 +288,13 @@ impl<const DEPTH: u8> SparseMerkleTree<DEPTH> for SimpleSmt<DEPTH> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_value(&self, key: &LeafIndex<DEPTH>) -> Word {
|
||||||
|
let leaf_pos = key.value();
|
||||||
|
|
||||||
|
*self.leaves.get(&leaf_pos)
|
||||||
|
.unwrap_or(&Self::EMPTY_VALUE)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_leaf(&self, key: &LeafIndex<DEPTH>) -> Word {
|
fn get_leaf(&self, key: &LeafIndex<DEPTH>) -> Word {
|
||||||
let leaf_pos = key.value();
|
let leaf_pos = key.value();
|
||||||
match self.leaves.get(&leaf_pos) {
|
match self.leaves.get(&leaf_pos) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue