pub fn edit_distance(search_chars: &Vec<char>, known_term: &str) -> usize
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 first Vec<char> to compare, in most time search_term will not change, so we would like to share the same Vec<char> between multiple calls. you could use search_string.chars().collect::<Vec<_>>() to convert a string to a Vec<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);