| Crates.io | agnostic-levenshtein |
| lib.rs | agnostic-levenshtein |
| version | 0.1.3 |
| created_at | 2025-02-01 06:09:59.123319+00 |
| updated_at | 2025-02-10 15:18:40.902599+00 |
| description | Levenshtein distance for ASCII or Unicode strings |
| homepage | |
| repository | https://github.com/theodore-s-beers/agnostic-levenshtein |
| max_upload_size | |
| id | 1538223 |
| size | 7,073 |
After doing the LeetCode problem on the edit distance between two strings—which in this case refers to the Levenshtein distance—I became quite enamored of the algorithm and wanted to write my own implementation in Rust. That's all this is.
I wrote my version such that the function edit_distance takes three arguments: two
&str and a bool flag for "ASCII mode." When this flag is set, the algorithm will
work directly with the bytes of the strings, rather than building Vecs of their 32-bit
(i.e., UTF-32) char values. This should be faster and avoid some allocation, as far as
I understand. I wonder if there might be a more efficient approach for the Unicode case.
Either way, the return value is the Levenshtein distance as u32. It may be worth
noting that input strings of length greater than u32::MAX will not yield correct
results—though I can hardly imagine that problem arising in practice.