Skip to content

Commit

Permalink
matchfinder: penalize score for overlapping matches
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalholm committed Jan 9, 2024
1 parent a8d524a commit 265f3af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion matchfinder/m4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
16 changes: 15 additions & 1 deletion matchfinder/multihash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 265f3af

Please sign in to comment.