Skip to content

Commit

Permalink
copy common files (golangci-lint: enable the intrange linter)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrre committed Aug 3, 2024
1 parent 015967c commit efc5ef1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ linters:
- "ineffassign"
- "interfacebloat"
# - "interfacer" # Archived.
- intrange
# - "ireturn" # Too many false positive.
# - "lll" # We don't use punch cards anymore.
- "loggercheck"
Expand Down
6 changes: 3 additions & 3 deletions geohash.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
for i := range base32Lookup {
base32Lookup[i] = -1
}
for i := 0; i < len(base32); i++ {
for i := range len(base32) {
base32Lookup[base32[i]] = i
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@ func Encode(lat, lon float64, precision int) string {
var buf [encodeMaxPrecision]byte
box := defaultBox
even := true
for i := 0; i < precision; i++ {
for i := range precision {
ci := 0
for mask := 1 << 4; mask != 0; mask >>= 1 {
var r *Range
Expand Down Expand Up @@ -85,7 +85,7 @@ func Encode(lat, lon float64, precision int) string {
func Decode(gh string) (Box, error) {
box := defaultBox
even := true
for i := 0; i < len(gh); i++ {
for i := range len(gh) {
ci := base32Lookup[gh[i]]
if ci == -1 {
return box, fmt.Errorf("geohash decode '%s': invalid character at index %d", gh, i)
Expand Down
36 changes: 18 additions & 18 deletions geohash_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
)

func BenchmarkEncode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
Encode(testPoint.Lat, testPoint.Lon, testPrecision)
}
}

func BenchmarkDecode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
_, err := Decode(testGeohash)
if err != nil {
assert.NoError(b, err)
Expand All @@ -28,7 +28,7 @@ func BenchmarkDecode(b *testing.B) {
}

func BenchmarkNeighbors(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
_, err := GetNeighbors(testGeohash)
if err != nil {
assert.NoError(b, err)
Expand All @@ -37,79 +37,79 @@ func BenchmarkNeighbors(b *testing.B) {
}

func BenchmarkCodeforEncode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
codefor_geohash.Encode(testPoint.Lat, testPoint.Lon)
}
}

func BenchmarkCodeforDecode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
codefor_geohash.Decode(testGeohash)
}
}

func BenchmarkTomiHiltunenEncode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
tomi_hiltunen_geohash.EncodeWithPrecision(testPoint.Lat, testPoint.Lon, testPrecision)
}
}

func BenchmarkTomiHiltunenDecode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
tomi_hiltunen_geohash.Decode(testGeohash)
}
}

func BenchmarkTomiHiltunenNeighbors(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
tomi_hiltunen_geohash.CalculateAllAdjacent(testGeohash)
}
}

func BenchmarkBroadyEncode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
broadygeohash.Encode(testPoint.Lat, testPoint.Lon)
}
}

func BenchmarkBroadyDecode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
broadygeohash.Decode(testGeohash)
}
}

func BenchmarkFanixkEncode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
fanixk_geohash.PrecisionEncode(testPoint.Lat, testPoint.Lon, testPrecision)
}
}

func BenchmarkFanixkDecode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
fanixk_geohash.DecodeBoundingBox(testGeohash)
}
}

func BenchmarkFanixkNeighbors(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
fanixk_geohash.Neighbors(testGeohash)
}
}

func BenchmarkMmcloughlinEncode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
mmcloughlin_geohash.EncodeWithPrecision(testPoint.Lat, testPoint.Lon, testPrecision)
}
}

func BenchmarkMmcloughlinDecode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
mmcloughlin_geohash.BoundingBox(testGeohash)
}
}

func BenchmarkMmcloughlinNeighbors(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
fanixk_geohash.Neighbors(testGeohash)
}
}
Expand All @@ -122,13 +122,13 @@ func BenchmarkThe42CartconvertEncode(b *testing.B) {
El: the42_cartconvert_geohash.DefaultEllipsoid,
}
precision := byte(testPrecision)
for i := 0; i < b.N; i++ {
for range b.N {
the42_cartconvert_geohash.LatLongToGeoHashBits(pc, precision)
}
}

func BenchmarkThe42CartconvertDecode(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
_, err := the42_cartconvert_geohash.GeoHashToLatLong(testGeohash, the42_cartconvert_geohash.DefaultEllipsoid)
if err != nil {
assert.NoError(b, err)
Expand Down

0 comments on commit efc5ef1

Please sign in to comment.