File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,21 @@ func (q *M4) FindMatches(dst []Match, src []byte) []Match {
167167 }
168168 }
169169
170- if q .score (currentMatch ) <= q .score (matches [0 ]) {
170+ if currentMatch .End - currentMatch .Start < q .MinLength {
171+ continue
172+ }
173+
174+ overlapPenalty := 0
175+ if matches [0 ] != (absoluteMatch {}) {
176+ overlapPenalty = 275
177+ if currentMatch .Start <= matches [1 ].End {
178+ // This match would completely replace the previous match,
179+ // so there is no penalty for overlap.
180+ overlapPenalty = 0
181+ }
182+ }
183+
184+ if q .score (currentMatch ) <= q .score (matches [0 ])+ overlapPenalty {
171185 continue
172186 }
173187
Original file line number Diff line number Diff line change @@ -172,7 +172,21 @@ func (q *MultiHash) FindMatches(dst []Match, src []byte) []Match {
172172 }
173173 }
174174
175- if currentMatch == (absoluteMatch {}) || q .score (currentMatch ) <= q .score (matches [0 ]) {
175+ if currentMatch .End - currentMatch .Start < q .MinLength {
176+ continue
177+ }
178+
179+ overlapPenalty := 0
180+ if matches [0 ] != (absoluteMatch {}) {
181+ overlapPenalty = 275
182+ if currentMatch .Start <= matches [1 ].End {
183+ // This match would completely replace the previous match,
184+ // so there is no penalty for overlap.
185+ overlapPenalty = 0
186+ }
187+ }
188+
189+ if q .score (currentMatch ) <= q .score (matches [0 ])+ overlapPenalty {
176190 continue
177191 }
178192
You can’t perform that action at this time.
0 commit comments