Skip to main content

edit_distance

Function edit_distance 

Source
pub(crate) fn edit_distance(a: &str, b: &str) -> usize
Expand description

Byte-level edit distance counting an adjacent transposition as one edit (optimal string alignment, the restricted Damerau-Levenshtein variant).

Callers only pass identifier-alphabet names (directive targets, kwarg keys, reference labels, citation keys), all ASCII, so byte distance equals character distance and case differences count as real edits. Charging a swapped pair one edit instead of two matters at the conservative nearest_match bound: wdithwidth is a single transposition, while two substitutions would push it past the len / 3 threshold for a five-byte key.

Storage is three reusable rows — current, previous, and the row before that (the transposition rule reaches two rows back): curr[j] holds the distance from the processed prefix of a to b[..j].