matchfinder: penalize score for overlapping matches

This commit is contained in:
Andy Balholm 2024-01-09 06:03:56 -08:00
parent a8d524a96d
commit 265f3afc2a
2 changed files with 30 additions and 2 deletions

View File

@ -167,7 +167,21 @@ func (q *M4) FindMatches(dst []Match, src []byte) []Match {
} }
} }
if q.score(currentMatch) <= q.score(matches[0]) { if currentMatch.End-currentMatch.Start < q.MinLength {
continue
}
overlapPenalty := 0
if matches[0] != (absoluteMatch{}) {
overlapPenalty = 275
if currentMatch.Start <= matches[1].End {
// This match would completely replace the previous match,
// so there is no penalty for overlap.
overlapPenalty = 0
}
}
if q.score(currentMatch) <= q.score(matches[0])+overlapPenalty {
continue continue
} }

View File

@ -172,7 +172,21 @@ func (q *MultiHash) FindMatches(dst []Match, src []byte) []Match {
} }
} }
if currentMatch == (absoluteMatch{}) || q.score(currentMatch) <= q.score(matches[0]) { if currentMatch.End-currentMatch.Start < q.MinLength {
continue
}
overlapPenalty := 0
if matches[0] != (absoluteMatch{}) {
overlapPenalty = 275
if currentMatch.Start <= matches[1].End {
// This match would completely replace the previous match,
// so there is no penalty for overlap.
overlapPenalty = 0
}
}
if q.score(currentMatch) <= q.score(matches[0])+overlapPenalty {
continue continue
} }