summaryrefslogtreecommitdiff
path: root/src/geo.h
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-06-22 18:08:06 +0200
committerantirez <antirez@gmail.com>2015-06-23 08:42:57 +0200
commit0b93139048c9e541feeaeacb79a604f50f6a2149 (patch)
tree54acfd01290e72d7b66fc32cd093dd6bb8110073 /src/geo.h
parent3d9031eda43c3018244c1e0495a4cfb2ef606974 (diff)
downloadredis-0b93139048c9e541feeaeacb79a604f50f6a2149.tar.gz
Geo: big refactoring of geo.c, zset.[ch] removed.
This commit simplifies the implementation in a few ways: 1. zsetScore implementation improved a bit and moved into t_zset.c where is now also used to implement the ZSCORE command. 2. Range extraction from the sorted set remains a separated implementation from the one in t_zset.c, but was hyper-specialized in order to avoid accumulating results into a list and remove the ones outside the radius. 3. A new type is introduced: geoArray, which can accumulate geoPoint structures in a vector with power of two expansion policy. This is useful since we have to call qsort() against it before returning the result to the user. 4. As a result of 1, 2, 3, the two files zset.c and zset.h are now removed, including the function to merge two lists (now handled with functions that can add elements to existing geoArray arrays) and the machinery used in order to pass zset results. 5. geoPoint structure simplified because of the general code structure simplification, so we no longer need to take references to objects. 6. Not counting the JSON removal the refactoring removes 200 lines of code for the same functionalities, with a simpler to read implementation. 7. GEORADIUS is now 2.5 times faster testing with 10k elements and a radius resulting in 124 elements returned. However this is mostly a side effect of the refactoring and simplification. More speed gains can be achieved by trying to optimize the code.
Diffstat (limited to 'src/geo.h')
-rw-r--r--src/geo.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/geo.h b/src/geo.h
index 9aa85cf9d..9cd1f56b4 100644
--- a/src/geo.h
+++ b/src/geo.h
@@ -9,13 +9,20 @@ void geoRadiusByMemberCommand(redisClient *c);
void geoRadiusCommand(redisClient *c);
void geoAddCommand(redisClient *c);
-struct geoPoint {
+/* Structures used inside geo.c in order to represent points and array of
+ * points on the earth. */
+typedef struct geoPoint {
double latitude;
double longitude;
double dist;
- char *set;
+ double score;
char *member;
- void *userdata;
-};
+} geoPoint;
+
+typedef struct geoArray {
+ struct geoPoint *array;
+ size_t buckets;
+ size_t used;
+} geoArray;
#endif