Skip to content

Commit

Permalink
Apply gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
samsalisbury committed Apr 3, 2016
1 parent c56542a commit 1a0de75
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion jaro-winkler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ func JaroWinkler(a, b string, boostThreshold float64, prefixSize int) float64 {
}
}

return j + 0.1 * prefixMatch * (1.0 - j)
return j + 0.1*prefixMatch*(1.0-j)
}
10 changes: 5 additions & 5 deletions jaro.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ func Jaro(a, b string) float64 {
lb := float64(len(b))

// match range = max(len(a), len(b)) / 2 - 1
matchRange := int(math.Floor(math.Max(la, lb) / 2.0)) - 1
matchRange = int(math.Max(0, float64(matchRange - 1)))
matchRange := int(math.Floor(math.Max(la, lb)/2.0)) - 1
matchRange = int(math.Max(0, float64(matchRange-1)))
var matches, halfs float64
transposed := make([]bool, len(b))

for i := 0; i < len(a); i++ {
start := int(math.Max(0, float64(i-matchRange)))
end := int(math.Min(lb - 1, float64(i+matchRange)))
end := int(math.Min(lb-1, float64(i+matchRange)))

for j := start; j <= end; j++ {
if transposed[j] {
Expand All @@ -38,7 +38,7 @@ func Jaro(a, b string) float64 {
return 0
}

transposes := math.Floor(float64(halfs/2))
transposes := math.Floor(float64(halfs / 2))

return ((matches/la) + (matches/lb) + (matches-transposes)/matches) / 3.0
return ((matches / la) + (matches / lb) + (matches-transposes)/matches) / 3.0
}
2 changes: 1 addition & 1 deletion tests/hamming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package tests

import (
"fmt"
"testing"
"github.com/xrash/smetrics"
"testing"
)

func TestHamming(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/jaro-winkler_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tests

import (
"testing"
"fmt"
"github.com/xrash/smetrics"
"testing"
)

func TestJaroWinkler(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/jaro_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tests

import (
"testing"
"fmt"
"github.com/xrash/smetrics"
"testing"
)

func TestJaro(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/soundex_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tests

import (
"testing"
"fmt"
"github.com/xrash/smetrics"
"testing"
)

func TestSoundex(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions tests/testcases.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ type jarocase struct {
}

type levenshteincase struct {
s string
t string
s string
t string
icost int
dcost int
scost int
r int
r int
}

type soundexcase struct {
Expand All @@ -21,7 +21,7 @@ type soundexcase struct {
}

type hammingcase struct {
a string
b string
a string
b string
diff int
}
2 changes: 1 addition & 1 deletion tests/ukkonen_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tests

import (
"testing"
"fmt"
"github.com/xrash/smetrics"
"testing"
)

func TestUkkonen(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/wagner-fischer_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tests

import (
"testing"
"fmt"
"github.com/xrash/smetrics"
"testing"
)

func TestWagnerFischer(t *testing.T) {
Expand Down
26 changes: 13 additions & 13 deletions ukkonen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ func Ukkonen(a, b string, icost, dcost, scost int) int {

if icost < dcost && icost < scost {
lowerCost = icost
} else if (dcost < scost) {
} else if dcost < scost {
lowerCost = dcost
} else {
lowerCost = scost
}

infinite := math.MaxInt32/2
infinite := math.MaxInt32 / 2

if len(a) > len(b) {
tmp := b
Expand All @@ -30,24 +30,24 @@ func Ukkonen(a, b string, icost, dcost, scost int) int {
t := (len(b) - len(a) + 1) * lowerCost

for {
if (t/lowerCost) < (len(b) - len(a)) {
if (t / lowerCost) < (len(b) - len(a)) {
continue
}

// This is the right damn thing since the original Ukkonen
// This is the right damn thing since the original Ukkonen
// paper minimizes the expression result only, but the uncommented version
// doesn't need to deal with floats so it's faster.
// p = int(math.Floor(0.5*((float64(t)/float64(lowerCost)) - float64(len(b) - len(a)))))
p = ((t/lowerCost) - (len(b) - len(a))) / 2
p = ((t / lowerCost) - (len(b) - len(a))) / 2

k = -p
kprime = k

rowlength := (len(b) - len(a)) + (2*p)
rowlength := (len(b) - len(a)) + (2 * p)

r = make([]int, rowlength + 2)
r = make([]int, rowlength+2)

for i := 0; i < rowlength + 2; i++ {
for i := 0; i < rowlength+2; i++ {
r[i] = infinite
}

Expand All @@ -56,7 +56,7 @@ func Ukkonen(a, b string, icost, dcost, scost int) int {
if i == j+k && i == 0 {
r[j] = 0
} else {
if (j-1 < 0) {
if j-1 < 0 {
ins = infinite
} else {
ins = r[j-1] + icost
Expand All @@ -73,7 +73,7 @@ func Ukkonen(a, b string, icost, dcost, scost int) int {

if ins < del && ins < sub {
r[j] = ins
} else if (del < sub) {
} else if del < sub {
r[j] = del
} else {
r[j] = sub
Expand All @@ -83,12 +83,12 @@ func Ukkonen(a, b string, icost, dcost, scost int) int {
k++
}

if r[(len(b) - len(a)) + (2 * p) + kprime] <= t {
break;
if r[(len(b)-len(a))+(2*p)+kprime] <= t {
break
} else {
t *= 2
}
}

return r[(len(b) - len(a)) + (2 * p) + kprime]
return r[(len(b)-len(a))+(2*p)+kprime]
}
10 changes: 5 additions & 5 deletions wagner-fischer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ func WagnerFischer(a, b string, icost, dcost, scost int) int {
// Compute the lower of the insert, deletion and substitution costs.
if icost < dcost && icost < scost {
lowerCost = icost
} else if (dcost < scost) {
} else if dcost < scost {
lowerCost = dcost
} else {
lowerCost = scost
}

// Allocate the array that will hold the last row.
row1 := make([]int, len(a) + 1)
row2 := make([]int, len(a) + 1)
row1 := make([]int, len(a)+1)
row2 := make([]int, len(a)+1)
var tmp []int

// Initialize the arrays.
Expand All @@ -44,7 +44,7 @@ func WagnerFischer(a, b string, icost, dcost, scost int) int {

if ins < del && ins < sub {
row2[j] = ins
} else if (del < sub) {
} else if del < sub {
row2[j] = del
} else {
row2[j] = sub
Expand All @@ -59,5 +59,5 @@ func WagnerFischer(a, b string, icost, dcost, scost int) int {
}

// Because we swapped the rows, the final result is in row1 instead of row2.
return row1[len(row1) - 1]
return row1[len(row1)-1]
}

0 comments on commit 1a0de75

Please sign in to comment.