make PrecomputedSubtrees more generic
This commit is contained in:
parent
11f3d49115
commit
cb8a5d2cd2
1 changed files with 7 additions and 6 deletions
|
@ -350,10 +350,11 @@ pub(crate) trait SparseMerkleTree<const DEPTH: u8> {
|
|||
/// The length `path` is guaranteed to be equal to `DEPTH`
|
||||
fn path_and_leaf_to_opening(path: MerklePath, leaf: Self::Leaf) -> Self::Opening;
|
||||
|
||||
#[cfg_attr(not(test), allow(dead_code))]
|
||||
fn sorted_pairs_to_leaves(
|
||||
pairs: Vec<(Self::Key, Self::Value)>,
|
||||
) -> PrecomputedSubtrees<Self::Leaf> {
|
||||
let mut accumulator: PrecomputedSubtrees<Self::Leaf> = Default::default();
|
||||
) -> PrecomputedSubtrees<u64, Self::Leaf> {
|
||||
let mut accumulator: PrecomputedSubtrees<u64, Self::Leaf> = Default::default();
|
||||
|
||||
// The kv-pairs we've seen so far that correspond to a single leaf.
|
||||
let mut current_leaf_buffer: Vec<(Self::Key, Self::Value)> = Default::default();
|
||||
|
@ -632,14 +633,14 @@ impl SubtreeLeaf {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PrecomputedSubtrees<L> {
|
||||
pub struct PrecomputedSubtrees<K, L> {
|
||||
/// Literal leaves to be added to the sparse Merkle tree's internal mapping.
|
||||
pub nodes: BTreeMap<u64, L>,
|
||||
pub nodes: BTreeMap<K, L>,
|
||||
/// "Conceptual" leaves that will be used for computations.
|
||||
pub leaves: Vec<Vec<SubtreeLeaf>>,
|
||||
}
|
||||
|
||||
impl<L> PrecomputedSubtrees<L> {
|
||||
impl<K, L> PrecomputedSubtrees<K, L> {
|
||||
pub fn add_leaf(&mut self, leaf: SubtreeLeaf) {
|
||||
let last_subtree = match self.leaves.last_mut() {
|
||||
// Base case.
|
||||
|
@ -670,7 +671,7 @@ impl<L> PrecomputedSubtrees<L> {
|
|||
}
|
||||
|
||||
// Derive requires `L` to impl Default, even though we don't actually need that.
|
||||
impl<L> Default for PrecomputedSubtrees<L> {
|
||||
impl<K, L> Default for PrecomputedSubtrees<K, L> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
nodes: Default::default(),
|
||||
|
|
Loading…
Add table
Reference in a new issue