mirror of
https://github.com/arnaucube/miden-crypto.git
synced 2026-01-09 15:41:30 +01:00
Introduce SimpleSmt::with_contiguous_leaves() (#227)
* with_contiguous_leaves * test
This commit is contained in:
committed by
Bobbin Threadbare
parent
894e20fe0c
commit
9e77a7c9b7
@@ -104,6 +104,22 @@ impl SimpleSmt {
|
|||||||
Ok(tree)
|
Ok(tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Wrapper around [`SimpleSmt::with_leaves`] which inserts leaves at contiguous indices
|
||||||
|
/// starting at index 0.
|
||||||
|
pub fn with_contiguous_leaves<R, I>(depth: u8, entries: R) -> Result<Self, MerkleError>
|
||||||
|
where
|
||||||
|
R: IntoIterator<IntoIter = I>,
|
||||||
|
I: Iterator<Item = Word> + ExactSizeIterator,
|
||||||
|
{
|
||||||
|
Self::with_leaves(
|
||||||
|
depth,
|
||||||
|
entries
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(idx, word)| (idx.try_into().expect("tree max depth is 2^8"), word)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// PUBLIC ACCESSORS
|
// PUBLIC ACCESSORS
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,21 @@ fn build_sparse_tree() {
|
|||||||
assert_eq!(old_value, EMPTY_WORD);
|
assert_eq!(old_value, EMPTY_WORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tests that [`SimpleSmt::with_contiguous_leaves`] works as expected
|
||||||
|
#[test]
|
||||||
|
fn build_contiguous_tree() {
|
||||||
|
let tree_with_leaves = SimpleSmt::with_leaves(
|
||||||
|
2,
|
||||||
|
[0, 1, 2, 3].into_iter().zip(digests_to_words(&VALUES4).into_iter()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let tree_with_contiguous_leaves =
|
||||||
|
SimpleSmt::with_contiguous_leaves(2, digests_to_words(&VALUES4).into_iter()).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(tree_with_leaves, tree_with_contiguous_leaves);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_depth2_tree() {
|
fn test_depth2_tree() {
|
||||||
let tree =
|
let tree =
|
||||||
|
|||||||
Reference in New Issue
Block a user