Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
03ce1896
Commit
03ce1896
authored
Jun 24, 2015
by
antirez
Browse files
Geo: explain increment magic in membersOfGeoHashBox().
parent
5fd756bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/geo.c
View file @
03ce1896
...
...
@@ -269,6 +269,26 @@ int geoGetPointsInRange(robj *zobj, double min, double max, double lat, double l
int
membersOfGeoHashBox
(
robj
*
zobj
,
GeoHashBits
hash
,
geoArray
*
ga
,
double
lat
,
double
lon
,
double
radius
)
{
GeoHashFix52Bits
min
,
max
;
/* We want to compute the sorted set scores that will include all the
* elements inside the specified Geohash 'hash', which has as many
* bits as specified by hash.step * 2.
*
* So if step is, for example, 3, and the hash value in binary
* is 101010, since our score is 52 bits we want every element which
* is in binary: 101010?????????????????????????????????????????????
* Where ? can be 0 or 1.
*
* To get the min score we just use the initial hash value left
* shifted enough to get the 52 bit value. Later we increment the
* 6 bit prefis (see the hash.bits++ statement), and get the new
* prefix: 101011, which we align again to 52 bits to get the maximum
* value (which is excluded from the search). So we get everything
* between the two following scores (represented in binary):
*
* 1010100000000000000000000000000000000000000000000000 (included)
* and
* 1010110000000000000000000000000000000000000000000000 (excluded).
*/
min
=
geohashAlign52Bits
(
hash
);
hash
.
bits
++
;
max
=
geohashAlign52Bits
(
hash
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment