improve fuzzy group minimization in some cases
This one was quite hard:
On pattern "besh", find
benches/shared
^^      ^^
@@ -99,6 +99,7 @@ impl FuzzyPattern {
break;
}
if cand_chars[cand_idx-rev_idx] == self.chars[pat_idx-rev_idx] {
+ // we move the pos forward
pos[pat_idx-rev_idx] = cand_idx-rev_idx;
} else {
break;
@@ -126,10 +127,19 @@ impl FuzzyPattern {
if pos[idx] > 1 + pos[idx-1] {
nb_holes += 1;
if idx > 1 && pos[idx-1] > 1 + pos[idx-2] {
+ // we improve a simple case: the one of a singleton which was created
+ // by pushing forward a char
+ if cand_chars[pos[idx-2]+1] == cand_chars[pos[idx-1]] {
+ // in some cases we're really removing another singletons but
+ // let's forget this
+ pos[idx-1] = pos[idx-2]+1;
+ nb_holes -= 1;
+ } else {
nb_singled_chars += 1;
}
}
}
+ }
if nb_holes > self.max_nb_holes {
return MatchSearchResult::None;
}
@@ -270,6 +280,11 @@ mod fuzzy_pattern_tests {
"brbroorrbbbbbrrooorobrototooooot.txt",
" ^^^ ^^ ",
);
+ check_pos(
+ "besh",
+ "benches/shared",
+ "^^ ^^ ",
+ );
}
/// check that the scores of all names are strictly decreasing
