Function didyoumean::edit_distance
source · [−]Expand description
Return the edit distance between search_term
and known_term
.
Currently implemented using a modified version of
Levenshtein distance.
Arguments
search_chars
- The firstVec<char>
to compare, in most time search_term will not change, so we would like to share the sameVec<char>
between multiple calls. you could usesearch_string.chars().collect::<Vec<_>>()
to convert a string to aVec<char>
known_term
- The second string to compare
Examples
let dist = edit_distance(&"sitting".chars().collect::<Vec<_>>(), "kitten");
assert_eq!(dist, 3);
assert_eq!(edit_distance(&"geek".chars().collect::<Vec<_>>(), "gesek"), 1);
assert_eq!(edit_distance(&"cat".chars().collect::<Vec<_>>(), "cut"), 1);
assert_eq!(edit_distance(&"sunday".chars().collect::<Vec<_>>(), "saturday"), 3);
assert_eq!(edit_distance(&"tset".chars().collect::<Vec<_>>(), "test"), 1);