Skip to content

Commit

Permalink
push
Browse files Browse the repository at this point in the history
  • Loading branch information
0xForerunner committed Mar 22, 2024
1 parent 75d053b commit 112f095
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/dynamic_merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@ impl<H: Hasher, Version: VersionMarker> DynamicMerkleTree<H, Version> {
}

pub fn push(&mut self, leaf: H::Hash) {
match self.storage.get_mut(self.num_leaves + 1) {
self.num_leaves += 1;
let index = index_from_leaf(self.num_leaves);
match self.storage.get_mut(index) {
Some(val) => *val = leaf,
None => {
self.reallocate();
self.storage[self.num_leaves + 1] = leaf;
}
}
self.num_leaves += 1;
}

pub fn set_leaf(&mut self, leaf: usize, value: H::Hash) {
Expand All @@ -199,8 +200,7 @@ impl<H: Hasher, Version: VersionMarker> DynamicMerkleTree<H, Version> {
let left_hash = self.storage.get(left)?;
let right_hash = self.storage[right];
let parent_index = parent(index);
let parent_hash = H::hash_node(left_hash, &right_hash);
self.storage[parent_index] = parent_hash;
self.storage[parent_index] = H::hash_node(left_hash, &right_hash);
index = parent_index;
}
}
Expand Down

0 comments on commit 112f095

Please sign in to comment.