Skip to content

Commit

Permalink
internal/eval: fix linter issues for new GEORADIUSBYMEMBER command
Browse files Browse the repository at this point in the history
  • Loading branch information
benbarten committed Dec 5, 2024
1 parent 1c4ac7e commit 275bcc6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
38 changes: 18 additions & 20 deletions internal/eval/geo/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand All @@ -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)

Check failure on line 231 in internal/eval/geo/geo.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)
Expand Down Expand Up @@ -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) {

Check failure on line 293 in internal/eval/geo/geo.go

View workflow job for this annotation

GitHub Actions / lint

paramTypeCombine: func(hash uint64, steps uint8) (minHash uint64, maxHash uint64) could be replaced with func(hash uint64, steps uint8) (minHash, maxHash uint64) (gocritic)
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.
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
6 changes: 2 additions & 4 deletions internal/eval/sortedset/sorted_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check failure on line 315 in internal/eval/sortedset/sorted_set.go

View workflow job for this annotation

GitHub Actions / lint

empty-lines: extra empty line at the start of a block (revive)

iterFunc := func(item btree.Item) bool {
ssi := item.(*Item)
Expand All @@ -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
}

Expand Down

0 comments on commit 275bcc6

Please sign in to comment.