summaryrefslogtreecommitdiffstats
path: root/src/pattern
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-05-11 21:07:11 +0200
committerCanop <cano.petrole@gmail.com>2021-05-11 21:07:11 +0200
commit779790f68e48b1209ec7483233d6fb7534faba7e (patch)
treef5dd285a07692461068d497e86d0bfbfe7ff9045 /src/pattern
parent613162c810a14dbd79adc125f89366315309a533 (diff)
improve fuzzy group minimization in some cases
This one was quite hard: On pattern "besh", find benches/shared ^^ ^^
Diffstat (limited to 'src/pattern')
-rw-r--r--src/pattern/fuzzy_pattern.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/pattern/fuzzy_pattern.rs b/src/pattern/fuzzy_pattern.rs
index 90c07ec..2bc28f1 100644
--- a/src/pattern/fuzzy_pattern.rs
+++ b/src/pattern/fuzzy_pattern.rs
@@ -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,7 +127,16 @@ impl FuzzyPattern {
if pos[idx] > 1 + pos[idx-1] {
nb_holes += 1;
if idx > 1 && pos[idx-1] > 1 + pos[idx-2] {
- nb_singled_chars += 1;
+ // 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;
+ }
}
}
}
@@ -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