Skip to content

Commit be4e8bc

Browse files
authored
chore(Internal): Remove the superseded cmp_keys (#902)
This function was superseded by the change in #847 to have `Word` compare lexicographically. This commit removes the last few uses and replaces them with calls to the `Ord` implementation for `Word` instead, simplifying the codebase.
1 parent 3a783d6 commit be4e8bc

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

miden-crypto/src/merkle/smt/full/concurrent/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use p3_maybe_rayon::prelude::*;
66

77
use super::{
88
EmptySubtreeRoots, InnerNode, InnerNodes, Leaves, MerkleError, MutationSet, NodeIndex,
9-
SMT_DEPTH, Smt, SmtLeaf, SparseMerkleTree, Word, leaf,
9+
SMT_DEPTH, Smt, SmtLeaf, SparseMerkleTree, Word,
1010
};
1111
use crate::merkle::smt::{Map, NodeMutation, NodeMutations, SmtLeafError};
1212

@@ -279,7 +279,7 @@ impl Smt {
279279
assert!(!pairs.is_empty());
280280

281281
if pairs.len() > 1 {
282-
pairs.sort_by(|(key_1, _), (key_2, _)| leaf::cmp_keys(*key_1, *key_2));
282+
pairs.sort_by(|(key_1, _), (key_2, _)| key_1.cmp(key_2));
283283
// Check for duplicates in a sorted list by comparing adjacent pairs
284284
Self::check_for_duplicate_keys(&pairs)?;
285285
Ok(Some(SmtLeaf::new_multiple(pairs).unwrap()))

miden-crypto/src/merkle/smt/full/leaf.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use alloc::{string::ToString, vec::Vec};
2-
use core::cmp::Ordering;
32

43
use super::EMPTY_WORD;
54
use crate::{
@@ -314,13 +313,13 @@ impl SmtLeaf {
314313
// This stays within MAX_LEAF_ENTRIES limit. We're only adding one entry to a
315314
// single leaf
316315
let mut pairs = vec![*kv_pair, (key, value)];
317-
pairs.sort_by(|(key_1, _), (key_2, _)| cmp_keys(*key_1, *key_2));
316+
pairs.sort_by(|(key_1, _), (key_2, _)| key_1.cmp(key_2));
318317
*self = SmtLeaf::Multiple(pairs);
319318
Ok(None)
320319
}
321320
},
322321
SmtLeaf::Multiple(kv_pairs) => {
323-
match kv_pairs.binary_search_by(|kv_pair| cmp_keys(kv_pair.0, key)) {
322+
match kv_pairs.binary_search_by(|kv_pair| kv_pair.0.cmp(&key)) {
324323
Ok(pos) => {
325324
let old_value = kv_pairs[pos].1;
326325
kv_pairs[pos].1 = value;
@@ -363,7 +362,7 @@ impl SmtLeaf {
363362
}
364363
},
365364
SmtLeaf::Multiple(kv_pairs) => {
366-
match kv_pairs.binary_search_by(|kv_pair| cmp_keys(kv_pair.0, key)) {
365+
match kv_pairs.binary_search_by(|kv_pair| kv_pair.0.cmp(&key)) {
367366
Ok(pos) => {
368367
let old_value = kv_pairs[pos].1;
369368

@@ -439,17 +438,3 @@ pub(crate) fn kv_to_elements((key, value): (Word, Word)) -> impl Iterator<Item =
439438

440439
key_elements.chain(value_elements)
441440
}
442-
443-
/// Compares two keys, compared element-by-element using their integer representations starting with
444-
/// the most significant element.
445-
pub(crate) fn cmp_keys(key_1: Word, key_2: Word) -> Ordering {
446-
for (v1, v2) in key_1.iter().zip(key_2.iter()).rev() {
447-
let v1 = (*v1).as_canonical_u64();
448-
let v2 = (*v2).as_canonical_u64();
449-
if v1 != v2 {
450-
return v1.cmp(&v2);
451-
}
452-
}
453-
454-
Ordering::Equal
455-
}

0 commit comments

Comments
 (0)