Skip to content

Commit f0992e3

Browse files
committed
Add comment explaining the lowercasing in the levenshtein distance calculation.
1 parent 4252879 commit f0992e3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/cargo/util/lev_distance.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use std::cmp;
22

33
pub fn lev_distance(me: &str, t: &str) -> usize {
4+
// Comparing the strings lowercased will result in a difference in capitalization being less distance away
5+
// than being a completely different letter. Otherwise `CHECK` is as far away from `check` as it
6+
// is from `build` (both with a distance of 5). For a single letter shortcut (e.g. `b` or `c`), they will
7+
// all be as far away from any capital single letter entry (all with a distance of 1).
8+
// By first lowercasing the strings, `C` and `c` are closer than `C` and `b`, for example.
49
let me = me.to_lowercase();
510
let t = t.to_lowercase();
611

0 commit comments

Comments
 (0)