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
f193b3ca
Commit
f193b3ca
authored
Jun 22, 2015
by
antirez
Browse files
Geo: removed bool usage from Geo code inside Redis
parent
73134f6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/geo.c
View file @
f193b3ca
...
@@ -47,36 +47,36 @@
...
@@ -47,36 +47,36 @@
/* ====================================================================
/* ====================================================================
* Helpers
* Helpers
* ==================================================================== */
* ==================================================================== */
static
inline
bool
decodeGeohash
(
double
bits
,
double
*
latlong
)
{
static
inline
int
decodeGeohash
(
double
bits
,
double
*
latlong
)
{
GeoHashBits
hash
=
{
.
bits
=
(
uint64_t
)
bits
,
.
step
=
GEO_STEP_MAX
};
GeoHashBits
hash
=
{
.
bits
=
(
uint64_t
)
bits
,
.
step
=
GEO_STEP_MAX
};
return
geohashDecodeToLatLongWGS84
(
hash
,
latlong
);
return
geohashDecodeToLatLongWGS84
(
hash
,
latlong
);
}
}
/* Input Argument Helper */
/* Input Argument Helper */
/* Take a pointer to the latitude arg then use the next arg for longitude */
/* Take a pointer to the latitude arg then use the next arg for longitude */
static
inline
bool
extractLatLongOrReply
(
redisClient
*
c
,
robj
**
argv
,
static
inline
int
extractLatLongOrReply
(
redisClient
*
c
,
robj
**
argv
,
double
*
latlong
)
{
double
*
latlong
)
{
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
if
(
getDoubleFromObjectOrReply
(
c
,
argv
[
i
],
latlong
+
i
,
NULL
)
!=
if
(
getDoubleFromObjectOrReply
(
c
,
argv
[
i
],
latlong
+
i
,
NULL
)
!=
REDIS_OK
)
{
REDIS_OK
)
{
return
false
;
return
0
;
}
}
}
}
return
true
;
return
1
;
}
}
/* Input Argument Helper */
/* Input Argument Helper */
/* Decode lat/long from a zset member's score */
/* Decode lat/long from a zset member's score */
static
bool
latLongFromMember
(
robj
*
zobj
,
robj
*
member
,
double
*
latlong
)
{
static
int
latLongFromMember
(
robj
*
zobj
,
robj
*
member
,
double
*
latlong
)
{
double
score
=
0
;
double
score
=
0
;
if
(
!
zsetScore
(
zobj
,
member
,
&
score
))
if
(
!
zsetScore
(
zobj
,
member
,
&
score
))
return
false
;
return
0
;
if
(
!
decodeGeohash
(
score
,
latlong
))
if
(
!
decodeGeohash
(
score
,
latlong
))
return
false
;
return
0
;
return
true
;
return
1
;
}
}
/* Input Argument Helper */
/* Input Argument Helper */
...
@@ -124,7 +124,7 @@ static void latLongToGeojsonAndReply(redisClient *c, struct geojsonPoint *gp,
...
@@ -124,7 +124,7 @@ static void latLongToGeojsonAndReply(redisClient *c, struct geojsonPoint *gp,
static
void
decodeGeohashToGeojsonBoundsAndReply
(
redisClient
*
c
,
static
void
decodeGeohashToGeojsonBoundsAndReply
(
redisClient
*
c
,
uint64_t
hashbits
,
uint64_t
hashbits
,
struct
geojsonPoint
*
gp
)
{
struct
geojsonPoint
*
gp
)
{
GeoHashArea
area
=
{
{
0
}
};
GeoHashArea
area
=
{
{
0
,
0
},{
0
,
0
},{
0
,
0
}
};
GeoHashBits
hash
=
{
.
bits
=
hashbits
,
.
step
=
GEO_STEP_MAX
};
GeoHashBits
hash
=
{
.
bits
=
hashbits
,
.
step
=
GEO_STEP_MAX
};
geohashDecodeWGS84
(
hash
,
&
area
);
geohashDecodeWGS84
(
hash
,
&
area
);
...
@@ -171,6 +171,7 @@ static list *membersOfAllNeighbors(robj *zobj, GeoHashRadius n, double x,
...
@@ -171,6 +171,7 @@ static list *membersOfAllNeighbors(robj *zobj, GeoHashRadius n, double x,
double
y
,
double
radius
)
{
double
y
,
double
radius
)
{
list
*
l
=
NULL
;
list
*
l
=
NULL
;
GeoHashBits
neighbors
[
9
];
GeoHashBits
neighbors
[
9
];
unsigned
int
i
;
neighbors
[
0
]
=
n
.
hash
;
neighbors
[
0
]
=
n
.
hash
;
neighbors
[
1
]
=
n
.
neighbors
.
north
;
neighbors
[
1
]
=
n
.
neighbors
.
north
;
...
@@ -184,7 +185,7 @@ static list *membersOfAllNeighbors(robj *zobj, GeoHashRadius n, double x,
...
@@ -184,7 +185,7 @@ static list *membersOfAllNeighbors(robj *zobj, GeoHashRadius n, double x,
/* For each neighbor (*and* our own hashbox), get all the matching
/* For each neighbor (*and* our own hashbox), get all the matching
* members and add them to the potential result list. */
* members and add them to the potential result list. */
for
(
int
i
=
0
;
i
<
sizeof
(
neighbors
)
/
sizeof
(
*
neighbors
);
i
++
)
{
for
(
i
=
0
;
i
<
sizeof
(
neighbors
)
/
sizeof
(
*
neighbors
);
i
++
)
{
list
*
r
;
list
*
r
;
if
(
HASHISZERO
(
neighbors
[
i
]))
if
(
HASHISZERO
(
neighbors
[
i
]))
...
@@ -213,7 +214,7 @@ static list *membersOfAllNeighbors(robj *zobj, GeoHashRadius n, double x,
...
@@ -213,7 +214,7 @@ static list *membersOfAllNeighbors(robj *zobj, GeoHashRadius n, double x,
listRewind
(
l
,
&
li
);
listRewind
(
l
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
while
((
ln
=
listNext
(
&
li
)))
{
struct
zipresult
*
zr
=
listNodeValue
(
ln
);
struct
zipresult
*
zr
=
listNodeValue
(
ln
);
GeoHashArea
area
=
{
{
0
}
};
GeoHashArea
area
=
{
{
0
,
0
},{
0
,
0
},{
0
,
0
}
};
GeoHashBits
hash
=
{
.
bits
=
(
uint64_t
)
zr
->
score
,
GeoHashBits
hash
=
{
.
bits
=
(
uint64_t
)
zr
->
score
,
.
step
=
GEO_STEP_MAX
};
.
step
=
GEO_STEP_MAX
};
...
@@ -433,31 +434,31 @@ static void geoRadiusGeneric(redisClient *c, int type) {
...
@@ -433,31 +434,31 @@ static void geoRadiusGeneric(redisClient *c, int type) {
sds
units
=
c
->
argv
[
base_args
-
2
+
1
]
->
ptr
;
sds
units
=
c
->
argv
[
base_args
-
2
+
1
]
->
ptr
;
/* Discover and populate all optional parameters. */
/* Discover and populate all optional parameters. */
bool
withdist
=
false
,
withhash
=
false
,
withcoords
=
false
,
int
withdist
=
0
,
withhash
=
0
,
withcoords
=
0
,
withgeojson
=
false
,
withgeojsonbounds
=
false
,
withgeojson
=
0
,
withgeojsonbounds
=
0
,
withgeojsoncollection
=
false
,
noproperties
=
false
;
withgeojsoncollection
=
0
,
noproperties
=
0
;
int
sort
=
SORT_NONE
;
int
sort
=
SORT_NONE
;
if
(
c
->
argc
>
base_args
)
{
if
(
c
->
argc
>
base_args
)
{
int
remaining
=
c
->
argc
-
base_args
;
int
remaining
=
c
->
argc
-
base_args
;
for
(
int
i
=
0
;
i
<
remaining
;
i
++
)
{
for
(
int
i
=
0
;
i
<
remaining
;
i
++
)
{
char
*
arg
=
c
->
argv
[
base_args
+
i
]
->
ptr
;
char
*
arg
=
c
->
argv
[
base_args
+
i
]
->
ptr
;
if
(
!
strncasecmp
(
arg
,
"withdist"
,
8
))
if
(
!
strncasecmp
(
arg
,
"withdist"
,
8
))
withdist
=
true
;
withdist
=
1
;
else
if
(
!
strcasecmp
(
arg
,
"withhash"
))
else
if
(
!
strcasecmp
(
arg
,
"withhash"
))
withhash
=
true
;
withhash
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"withcoord"
,
9
))
else
if
(
!
strncasecmp
(
arg
,
"withcoord"
,
9
))
withcoords
=
true
;
withcoords
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"withgeojsonbound"
,
16
))
else
if
(
!
strncasecmp
(
arg
,
"withgeojsonbound"
,
16
))
withgeojsonbounds
=
true
;
withgeojsonbounds
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"withgeojsoncollection"
,
21
))
else
if
(
!
strncasecmp
(
arg
,
"withgeojsoncollection"
,
21
))
withgeojsoncollection
=
true
;
withgeojsoncollection
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"withgeo"
,
7
)
||
else
if
(
!
strncasecmp
(
arg
,
"withgeo"
,
7
)
||
!
strcasecmp
(
arg
,
"geojson"
)
||
!
strcasecmp
(
arg
,
"json"
)
||
!
strcasecmp
(
arg
,
"geojson"
)
||
!
strcasecmp
(
arg
,
"json"
)
||
!
strcasecmp
(
arg
,
"withjson"
))
!
strcasecmp
(
arg
,
"withjson"
))
withgeojson
=
true
;
withgeojson
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"noprop"
,
6
)
||
else
if
(
!
strncasecmp
(
arg
,
"noprop"
,
6
)
||
!
strncasecmp
(
arg
,
"withoutprop"
,
11
))
!
strncasecmp
(
arg
,
"withoutprop"
,
11
))
noproperties
=
true
;
noproperties
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"asc"
,
3
)
||
else
if
(
!
strncasecmp
(
arg
,
"asc"
,
3
)
||
!
strncasecmp
(
arg
,
"sort"
,
4
))
!
strncasecmp
(
arg
,
"sort"
,
4
))
sort
=
SORT_ASC
;
sort
=
SORT_ASC
;
...
@@ -470,7 +471,7 @@ static void geoRadiusGeneric(redisClient *c, int type) {
...
@@ -470,7 +471,7 @@ static void geoRadiusGeneric(redisClient *c, int type) {
}
}
}
}
bool
withgeo
=
withgeojsonbounds
||
withgeojsoncollection
||
withgeojson
;
int
withgeo
=
withgeojsonbounds
||
withgeojsoncollection
||
withgeojson
;
/* Get all neighbor geohash boxes for our radius search */
/* Get all neighbor geohash boxes for our radius search */
GeoHashRadius
georadius
=
GeoHashRadius
georadius
=
...
@@ -617,9 +618,9 @@ void geoDecodeCommand(redisClient *c) {
...
@@ -617,9 +618,9 @@ void geoDecodeCommand(redisClient *c) {
NULL
)
!=
REDIS_OK
)
NULL
)
!=
REDIS_OK
)
return
;
return
;
bool
withgeojson
=
false
;
int
withgeojson
=
0
;
if
(
c
->
argc
==
3
)
if
(
c
->
argc
==
3
)
withgeojson
=
true
;
withgeojson
=
1
;
GeoHashArea
area
;
GeoHashArea
area
;
geohash
.
step
=
GEO_STEP_MAX
;
geohash
.
step
=
GEO_STEP_MAX
;
...
@@ -665,12 +666,12 @@ void geoEncodeCommand(redisClient *c) {
...
@@ -665,12 +666,12 @@ void geoEncodeCommand(redisClient *c) {
* - AND / OR -
* - AND / OR -
* optional: [geojson] */
* optional: [geojson] */
bool
withgeojson
=
false
;
int
withgeojson
=
0
;
for
(
int
i
=
3
;
i
<
c
->
argc
;
i
++
)
{
for
(
int
i
=
3
;
i
<
c
->
argc
;
i
++
)
{
char
*
arg
=
c
->
argv
[
i
]
->
ptr
;
char
*
arg
=
c
->
argv
[
i
]
->
ptr
;
if
(
!
strncasecmp
(
arg
,
"withgeo"
,
7
)
||
!
strcasecmp
(
arg
,
"geojson"
)
||
if
(
!
strncasecmp
(
arg
,
"withgeo"
,
7
)
||
!
strcasecmp
(
arg
,
"geojson"
)
||
!
strcasecmp
(
arg
,
"json"
)
||
!
strcasecmp
(
arg
,
"withjson"
))
{
!
strcasecmp
(
arg
,
"json"
)
||
!
strcasecmp
(
arg
,
"withjson"
))
{
withgeojson
=
true
;
withgeojson
=
1
;
break
;
break
;
}
}
}
}
...
...
src/zset.c
View file @
f193b3ca
...
@@ -13,13 +13,13 @@ int zslValueLteMax(double value, zrangespec *spec);
...
@@ -13,13 +13,13 @@ int zslValueLteMax(double value, zrangespec *spec);
* ==================================================================== */
* ==================================================================== */
/* zset access is mostly a copy/paste from zscoreCommand() */
/* zset access is mostly a copy/paste from zscoreCommand() */
bool
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
)
{
int
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
)
{
if
(
!
zobj
||
!
member
)
if
(
!
zobj
||
!
member
)
return
false
;
return
0
;
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
zzlFind
(
zobj
->
ptr
,
member
,
score
)
==
NULL
)
if
(
zzlFind
(
zobj
->
ptr
,
member
,
score
)
==
NULL
)
return
false
;
return
0
;
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_SKIPLIST
)
{
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_SKIPLIST
)
{
zset
*
zs
=
zobj
->
ptr
;
zset
*
zs
=
zobj
->
ptr
;
dictEntry
*
de
;
dictEntry
*
de
;
...
@@ -29,11 +29,11 @@ bool zsetScore(robj *zobj, robj *member, double *score) {
...
@@ -29,11 +29,11 @@ bool zsetScore(robj *zobj, robj *member, double *score) {
if
(
de
!=
NULL
)
{
if
(
de
!=
NULL
)
{
*
score
=
*
(
double
*
)
dictGetVal
(
de
);
*
score
=
*
(
double
*
)
dictGetVal
(
de
);
}
else
}
else
return
false
;
return
0
;
}
else
{
}
else
{
return
false
;
return
0
;
}
}
return
true
;
return
1
;
}
}
/* Largely extracted from genericZrangebyscoreCommand() in t_zset.c */
/* Largely extracted from genericZrangebyscoreCommand() in t_zset.c */
...
...
src/zset.h
View file @
f193b3ca
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
#define __ZSET_H__
#define __ZSET_H__
#include "redis.h"
#include "redis.h"
#include <stdbool.h>
#define ZR_LONG 1
#define ZR_LONG 1
#define ZR_STRING 2
#define ZR_STRING 2
...
@@ -17,7 +16,7 @@ struct zipresult {
...
@@ -17,7 +16,7 @@ struct zipresult {
};
};
/* Redis DB Access */
/* Redis DB Access */
bool
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
);
int
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
);
list
*
geozrangebyscore
(
robj
*
zobj
,
double
min
,
double
max
,
int
limit
);
list
*
geozrangebyscore
(
robj
*
zobj
,
double
min
,
double
max
,
int
limit
);
/* New list operation: append one list to another */
/* New list operation: append one list to another */
...
...
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