Skip to content

Commit

Permalink
Reducing to just 1 allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynom committed Jul 3, 2020
1 parent 91df0e6 commit 6e08967
Show file tree
Hide file tree
Showing 2 changed files with 417 additions and 7 deletions.
13 changes: 6 additions & 7 deletions finder/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ func NewJaro() Algorithm {
}

matchDistance = matchDistance/2 - 1
aMatches := make([]bool, len(a))
bMatches := make([]bool, len(b))
matchesCollected := make([]bool, len(a)+len(b))

var matches float64
var transpositions float64
Expand All @@ -89,15 +88,15 @@ func NewJaro() Algorithm {
}

for k := start; k < end; k++ {
if bMatches[k] {
if matchesCollected[k+len(a)] {
continue
}
if a[i] != b[k] {
continue
}

aMatches[i] = true
bMatches[k] = true
matchesCollected[i] = true
matchesCollected[k+len(a)] = true
matches++
break
}
Expand All @@ -109,11 +108,11 @@ func NewJaro() Algorithm {

k := 0
for i := range a {
if !aMatches[i] {
if !matchesCollected[i] {
continue
}

for !bMatches[k] {
for !matchesCollected[k+len(a)] {
k++
}

Expand Down
Loading

0 comments on commit 6e08967

Please sign in to comment.