Skip to content

Commit

Permalink
optimize Pattern.WeakEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
apetruhin committed May 9, 2024
1 parent 39110d8 commit be9523a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
)

const (
minWordLen = 2
minWordLen = 2
patternMaxDiff = 1
patternCheckFirstN = 100
)

var (
Expand Down Expand Up @@ -54,10 +56,13 @@ func (p *Pattern) WeakEqual(other *Pattern) bool {
return false
}
var diffs int
for i, ow := range other.words {
if p.words[i] != ow {
for i := range other.words {
if i > patternCheckFirstN {
return true
}
if p.words[i] != other.words[i] {
diffs++
if diffs > 1 {
if diffs > patternMaxDiff {
return false
}
}
Expand Down

0 comments on commit be9523a

Please sign in to comment.