Skip to content

Commit

Permalink
feat: HashBuilder::add-leaf-unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-rise committed Dec 2, 2024
1 parent 25c252f commit d4dae1b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/hash_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,21 @@ impl HashBuilder {
}

/// Adds a new leaf element and its value to the trie hash builder.
///
/// # Panics
///
/// Panics if the new key does not come after the current key.
pub fn add_leaf(&mut self, key: Nibbles, value: &[u8]) {
assert!(key > self.key, "add_leaf key {:?} self.key {:?}", key, self.key);
self.add_leaf_unchecked(key, value);
}

/// Adds a new leaf element and its value to the trie hash builder,
/// without checking the order of the new key. This is only for
/// performance-critical usage that guarantees keys are inserted
/// in sorted order.
pub fn add_leaf_unchecked(&mut self, key: Nibbles, value: &[u8]) {
debug_assert!(key > self.key, "add_leaf_unchecked key {:?} self.key {:?}", key, self.key);
if !self.key.is_empty() {
self.update(&key);
}
Expand Down

0 comments on commit d4dae1b

Please sign in to comment.