add comments and cleanup
This commit is contained in:
parent
a860a720ba
commit
7b4f436a30
1 changed files with 10 additions and 3 deletions
|
@ -190,6 +190,7 @@ fn find_best_match_for_name_impl(
|
||||||
|
|
||||||
let mut dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3);
|
let mut dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3);
|
||||||
let mut best = None;
|
let mut best = None;
|
||||||
|
// store the candidates with the same distance, only for `use_substring_score` current.
|
||||||
let mut next_candidates = vec![];
|
let mut next_candidates = vec![];
|
||||||
for c in candidates {
|
for c in candidates {
|
||||||
match if use_substring_score {
|
match if use_substring_score {
|
||||||
|
@ -200,19 +201,25 @@ fn find_best_match_for_name_impl(
|
||||||
Some(0) => return Some(*c),
|
Some(0) => return Some(*c),
|
||||||
Some(d) => {
|
Some(d) => {
|
||||||
if use_substring_score {
|
if use_substring_score {
|
||||||
|
if d < dist {
|
||||||
dist = d;
|
dist = d;
|
||||||
|
next_candidates.clear();
|
||||||
|
} else {
|
||||||
|
// `d == dist` here, we need to store the candidates with the same distance
|
||||||
|
// so we won't decrease the distance in the next loop.
|
||||||
|
}
|
||||||
next_candidates.push(*c);
|
next_candidates.push(*c);
|
||||||
best = Some(*c);
|
|
||||||
} else {
|
} else {
|
||||||
dist = d - 1;
|
dist = d - 1;
|
||||||
best = Some(*c);
|
|
||||||
}
|
}
|
||||||
|
best = Some(*c);
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if next_candidates.len() > 1 {
|
if next_candidates.len() > 1 {
|
||||||
|
debug_assert!(use_substring_score);
|
||||||
best = find_best_match_for_name_impl(
|
best = find_best_match_for_name_impl(
|
||||||
false,
|
false,
|
||||||
&next_candidates,
|
&next_candidates,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue