Skip to content

Commit 4d0a70f

Browse files
authored
refactor(Word): Remove LexicographicWord (#918)
The type was previously used to perform lexicographic comparisons between words, but that behavior is now encapsulated in the default `Ord` instance for word, so the type is unnecessary.
1 parent aff85a6 commit 4d0a70f

File tree

6 files changed

+27
-208
lines changed

6 files changed

+27
-208
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [BREAKING] Removed `AlgebraicSponge::merge_with_int()` method ([#894](https://github.com/0xMiden/crypto/pull/894)).
44
- Added the ability to configure the sync-to-disk behavior of the persistent backend using its config ([#912](https://github.com/0xMiden/crypto/pull/912)).
55
- Adds `LargeSmtForest::add_lineages` which provides an efficient means of adding multiple new lineages at once ([#910](https://github.com/0xMiden/crypto/pull/910)).
6+
- [BREAKING] Removed `LexicographicWord` as `Word` itself now implements the correct comparison behavior. Any place where the former is used should be able to seamlessly swap to the latter.
67

78
## 0.23.0 (2026-03-11)
89

miden-crypto/benches/word.rs

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! Comprehensive Word operation benchmarks
22
//!
33
//! This module benchmarks all Word operations implemented in the library
4-
//! with a focus on type conversions, serialization, and lexicographic ordering.
4+
//! with a focus on type conversions, serialization, and ordering.
55
//!
66
//! # Organization
77
//!
88
//! The benchmarks are organized by:
99
//! 1. Word creation and basic operations
1010
//! 2. Type conversions (bool, u8, u16, u32, u64)
1111
//! 3. Serialization and deserialization
12-
//! 4. Lexicographic ordering
12+
//! 4. Ordering (lexicographic)
1313
//! 5. Batch operations
1414
//!
1515
//! # Adding New Word Benchmarks
@@ -22,7 +22,7 @@
2222
2323
use criterion::{Criterion, criterion_group, criterion_main};
2424
// Import Word modules
25-
use miden_crypto::{Felt, LexicographicWord, Word};
25+
use miden_crypto::{Felt, Word};
2626

2727
// Import common utilities
2828
mod common;
@@ -198,82 +198,42 @@ benchmark_with_setup! {
198198
},
199199
}
200200

201-
// === Lexicographic Ordering Benchmarks ===
201+
// === Ordering Benchmarks ===
202202

203-
// Lexicographic word creation
204-
benchmark_with_setup! {
205-
word_lexicographic_new,
206-
DEFAULT_MEASUREMENT_TIME,
207-
DEFAULT_SAMPLE_SIZE,
208-
"new",
209-
|| {},
210-
|b: &mut criterion::Bencher| {
211-
b.iter(|| {
212-
for word in &TEST_WORDS {
213-
let _lex_word = LexicographicWord::new(*word);
214-
}
215-
})
216-
},
217-
}
218-
219-
// Lexicographic word access
220-
benchmark_with_setup_data! {
221-
word_lexicographic_access,
222-
DEFAULT_MEASUREMENT_TIME,
223-
DEFAULT_SAMPLE_SIZE,
224-
"inner_access",
225-
|| {
226-
let lex_words: Vec<LexicographicWord> =
227-
TEST_WORDS.iter().map(|w| LexicographicWord::new(*w)).collect();
228-
lex_words
229-
},
230-
|b: &mut criterion::Bencher, lex_words: &Vec<LexicographicWord>| {
231-
b.iter(|| {
232-
for lex_word in lex_words {
233-
let _inner = lex_word.inner();
234-
}
235-
})
236-
},
237-
}
238-
239-
// Lexicographic ordering comparisons
203+
// Word ordering comparisons (lexicographic)
240204
benchmark_with_setup_data! {
241-
word_lexicographic_ordering,
205+
word_cmp,
242206
DEFAULT_MEASUREMENT_TIME,
243207
DEFAULT_SAMPLE_SIZE,
244-
"partial_cmp",
208+
"cmp",
245209
|| {
246-
let lex_words: Vec<LexicographicWord> =
247-
TEST_WORDS.iter().map(|w| LexicographicWord::new(*w)).collect();
248-
lex_words
210+
TEST_WORDS.to_vec()
249211
},
250-
|b: &mut criterion::Bencher, lex_words: &Vec<LexicographicWord>| {
212+
|b: &mut criterion::Bencher, words: &Vec<Word>| {
251213
b.iter(|| {
252-
for i in 0..lex_words.len() {
253-
for j in i..lex_words.len() {
254-
let _result = lex_words[i].partial_cmp(&lex_words[j]);
214+
for i in 0..words.len() {
215+
for j in i..words.len() {
216+
let _result = words[i].cmp(&words[j]);
255217
}
256218
}
257219
})
258220
},
259221
}
260222

261-
// Lexicographic equality comparison
223+
// Word equality comparison
262224
benchmark_with_setup_data! {
263-
word_lexicographic_eq,
225+
word_eq,
264226
DEFAULT_MEASUREMENT_TIME,
265227
DEFAULT_SAMPLE_SIZE,
266228
"eq",
267229
|| {
268-
let lex_words: Vec<LexicographicWord> =
269-
TEST_WORDS.iter().map(|w| LexicographicWord::new(*w)).collect();
270-
lex_words
230+
TEST_WORDS.to_vec()
271231
},
272-
|b: &mut criterion::Bencher, lex_words: &Vec<LexicographicWord>| {
232+
|b: &mut criterion::Bencher, words: &Vec<Word>| {
273233
b.iter(|| {
274-
for i in 0..lex_words.len() {
275-
for j in 0..lex_words.len() {
276-
let _result = lex_words[i] == lex_words[j];
234+
for i in 0..words.len() {
235+
for j in 0..words.len() {
236+
let _result = words[i] == words[j];
277237
}
278238
}
279239
})
@@ -321,11 +281,9 @@ criterion_group!(
321281
// Serialization benchmarks
322282
word_to_hex,
323283
word_to_vec,
324-
// Lexicographic ordering benchmarks
325-
word_lexicographic_new,
326-
word_lexicographic_access,
327-
word_lexicographic_ordering,
328-
word_lexicographic_eq,
284+
// Ordering benchmarks
285+
word_cmp,
286+
word_eq,
329287
// Batch operations benchmarks
330288
word_batch_elements,
331289
);

miden-crypto/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod utils;
1616

1717
// RE-EXPORTS
1818
// ================================================================================================
19-
pub use miden_field::{Felt, LexicographicWord, Word, WordError, word};
19+
pub use miden_field::{Felt, Word, WordError, word};
2020

2121
pub mod field {
2222
//! Traits and utilities for working with the Goldilocks finite field (i.e.,

miden-field/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ pub use p3_field::{
3636
},
3737
integers::QuotientMap,
3838
};
39-
pub use word::{LexicographicWord, Word, WordError};
39+
pub use word::{Word, WordError};

miden-field/src/word/lexicographic.rs

Lines changed: 0 additions & 137 deletions
This file was deleted.

miden-field/src/word/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ use p3_field::integers::QuotientMap;
2525
use super::Felt;
2626
use crate::utils::bytes_to_hex_string;
2727

28-
mod lexicographic;
29-
pub use lexicographic::LexicographicWord;
30-
3128
#[cfg(test)]
3229
mod tests;
3330

@@ -322,8 +319,8 @@ impl Ord for Word {
322319
// though the field order is p = 2^64 - 2^32 + 1. This method canonicalizes to [0, p).
323320
//
324321
// We must iterate over and compare each element individually. A simple bytestring
325-
// comparison would be inappropriate because the `Word`s are represented in
326-
// "lexicographical" order.
322+
// comparison would be inappropriate because `Word`s internal representation is not
323+
// naturally lexicographically comparable.
327324
for (felt0, felt1) in self
328325
.iter()
329326
.rev()

0 commit comments

Comments
 (0)