diff --git a/internal/eval/geo/geo.go b/internal/eval/geo/geo.go index 1baa33990..de21193d6 100644 --- a/internal/eval/geo/geo.go +++ b/internal/eval/geo/geo.go @@ -91,7 +91,7 @@ func DecodeHash(hash float64) (lat, lon float64) { } // decodeHash decodes the geohash into latitude and longitude with the specified number of steps. -func decodeHash(hash uint64, steps uint8) (lat float64, lon float64) { +func decodeHash(hash uint64, steps uint8) (lat, lon float64) { hashSep := deinterleave64(hash) latScale := globalMaxLat - globalMinLat @@ -194,7 +194,7 @@ func geohashEstimateStepsByRadius(radius, lat float64) uint8 { } // boundingBox returns the bounding box for a given latitude, longitude and radius. -func boundingBox(lat, lon, radius float64) (float64, float64, float64, float64) { +func boundingBox(lat, lon, radius float64) (minLon, minLat, maxLon, maxLat float64) { latDelta := RadToDeg(radius / earthRadius) lonDeltaTop := RadToDeg(radius / earthRadius / math.Cos(DegToRad(lat+latDelta))) lonDeltaBottom := RadToDeg(radius / earthRadius / math.Cos(DegToRad(lat-latDelta))) @@ -204,30 +204,28 @@ func boundingBox(lat, lon, radius float64) (float64, float64, float64, float64) isSouthernHemisphere = true } - minLon := lon - lonDeltaTop + minLon = lon - lonDeltaTop if isSouthernHemisphere { minLon = lon - lonDeltaBottom } - maxLon := lon + lonDeltaTop + maxLon = lon + lonDeltaTop if isSouthernHemisphere { maxLon = lon + lonDeltaBottom } - minLat := lat - latDelta - maxLat := lat + latDelta + minLat = lat - latDelta + maxLat = lat + latDelta return minLon, minLat, maxLon, maxLat } // Area returns the geohashes of the area covered by a circle with a given radius. It returns the center hash // and the 8 surrounding hashes. The second return value is the number of steps used to cover the area. -func Area(centerHash, radius float64) ([9]uint64, uint8) { - var result [9]uint64 - +func Area(centerHash, radius float64) (result [9]uint64, steps uint8) { centerLat, centerLon := decodeHash(uint64(centerHash), maxSteps) minLon, minLat, maxLon, maxLat := boundingBox(centerLat, centerLon, radius) - steps := geohashEstimateStepsByRadius(radius, centerLat) + steps = geohashEstimateStepsByRadius(radius, centerLat) centerRadiusHash := encodeHash(centerLon, centerLat, steps) neighbors := geohashNeighbors(uint64(centerRadiusHash), steps) @@ -292,11 +290,11 @@ func Area(centerHash, radius float64) ([9]uint64, uint8) { // HashMinMax returns the min and max hashes for a given hash and steps. This can be used to get the range of hashes // that a given hash and a radius (steps) will cover. -func HashMinMax(hash uint64, steps uint8) (uint64, uint64) { - min := align52Bits(hash, steps) +func HashMinMax(hash uint64, steps uint8) (minHash uint64, maxHash uint64) { + minHash = align52Bits(hash, steps) hash++ - max := align52Bits(hash, steps) - return min, max + maxHash = align52Bits(hash, steps) + return minHash, maxHash } // align52Bits aligns the hash to 52 bits. @@ -403,10 +401,10 @@ func geohashMoveX(hash uint64, steps uint8, d int8) uint64 { zz := 0x5555555555555555 >> (64 - steps*2) if d > 0 { - x = x + uint64(zz+1) + x += uint64(zz + 1) } else { - x = x | uint64(zz) - x = x - uint64(zz+1) + x |= uint64(zz) + x -= uint64(zz + 1) } x &= (0xaaaaaaaaaaaaaaaa >> (64 - steps*2)) @@ -421,10 +419,10 @@ func geohashMoveY(hash uint64, steps uint8, d int8) uint64 { zz := uint64(0xaaaaaaaaaaaaaaaa) >> (64 - steps*2) if d > 0 { - y = y + (zz + 1) + y += (zz + 1) } else { - y = y | zz - y = y - (zz + 1) + y |= zz + y -= (zz + 1) } y &= (0x5555555555555555 >> (64 - steps*2)) diff --git a/internal/eval/sortedset/sorted_set.go b/internal/eval/sortedset/sorted_set.go index c5d927823..715914543 100644 --- a/internal/eval/sortedset/sorted_set.go +++ b/internal/eval/sortedset/sorted_set.go @@ -312,9 +312,7 @@ func DeserializeSortedSet(buf *bytes.Reader) (*Set, error) { // GetScoreRange returns a slice of members with scores between min and max, inclusive. // If withScores is true, the members will be returned with their scores. -func (ss *Set) GetMemberScoresInRange(minScore, maxScore float64, count, max int) ([]string, []float64) { - var members []string - var scores []float64 +func (ss *Set) GetMemberScoresInRange(minScore, maxScore float64, count, maxCount int) (members []string, scores []float64) { iterFunc := func(item btree.Item) bool { ssi := item.(*Item) @@ -328,7 +326,7 @@ func (ss *Set) GetMemberScoresInRange(minScore, maxScore float64, count, max int scores = append(scores, ssi.Score) count++ - if max > 0 && count >= max { + if maxCount > 0 && count >= maxCount { return false }