feat: export Merkle get_value() in the trait
This commit is contained in:
parent
52ab7bca97
commit
00e2be79a4
3 changed files with 22 additions and 6 deletions
|
@ -122,12 +122,7 @@ impl Smt {
|
||||||
|
|
||||||
/// Returns the value associated with `key`
|
/// Returns the value associated with `key`
|
||||||
pub fn get_value(&self, key: &RpoDigest) -> Word {
|
pub fn get_value(&self, key: &RpoDigest) -> Word {
|
||||||
let leaf_pos = LeafIndex::<SMT_DEPTH>::from(*key).value();
|
<Self as SparseMerkleTree<SMT_DEPTH>>::get_value(self, key)
|
||||||
|
|
||||||
match self.leaves.get(&leaf_pos) {
|
|
||||||
Some(leaf) => leaf.get_value(key).unwrap_or_default(),
|
|
||||||
None => EMPTY_WORD,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an opening of the leaf associated with `key`. Conceptually, an opening is a Merkle
|
/// Returns an opening of the leaf associated with `key`. Conceptually, an opening is a Merkle
|
||||||
|
@ -251,6 +246,15 @@ impl SparseMerkleTree<SMT_DEPTH> for Smt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_value(&self, key: &Self::Key) -> Self::Value {
|
||||||
|
let leaf_pos = LeafIndex::<SMT_DEPTH>::from(*key).value();
|
||||||
|
|
||||||
|
match self.leaves.get(&leaf_pos) {
|
||||||
|
Some(leaf) => leaf.get_value(key).unwrap_or_default(),
|
||||||
|
None => EMPTY_WORD,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,10 @@ 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. Recall that by definition, any key that hasn't been
|
||||||
|
/// updated is associated with [`Self::EMPTY_VALUE`].
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
|
@ -289,6 +289,14 @@ impl<const DEPTH: u8> SparseMerkleTree<DEPTH> for SimpleSmt<DEPTH> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_value(&self, key: &Self::Key) -> Self::Value {
|
||||||
|
let leaf_pos = key.value();
|
||||||
|
match self.leaves.get(&leaf_pos) {
|
||||||
|
Some(word) => *word,
|
||||||
|
None => 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