feat: add subset() to MerkleStore

This commit is contained in:
Bobbin Threadbare
2023-05-09 18:38:21 -07:00
parent e5aba870a2
commit 13aeda5a27
3 changed files with 195 additions and 71 deletions

View File

@@ -114,6 +114,28 @@ impl MerkleTree {
Ok(path.into())
}
// ITERATORS
// --------------------------------------------------------------------------------------------
/// Returns an iterator over the leaves of this [MerkleTree].
pub fn leaves(&self) -> core::slice::Iter<Word> {
let leaves_start = self.nodes.len() / 2;
self.nodes[leaves_start..].iter()
}
/// Returns n iterator over every inner node of this [MerkleTree].
///
/// The iterator order is unspecified.
pub fn inner_nodes(&self) -> InnerNodeIterator<'_> {
InnerNodeIterator {
nodes: &self.nodes,
index: 1, // index 0 is just padding, start at 1
}
}
// STATE MUTATORS
// --------------------------------------------------------------------------------------------
/// Replaces the leaf at the specified index with the provided value.
///
/// # Errors
@@ -149,16 +171,6 @@ impl MerkleTree {
Ok(())
}
/// Returns n iterator over every inner node of this [MerkleTree].
///
/// The iterator order is unspecified.
pub fn inner_nodes(&self) -> InnerNodeIterator<'_> {
InnerNodeIterator {
nodes: &self.nodes,
index: 1, // index 0 is just padding, start at 1
}
}
}
// ITERATORS