"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/geo.c" between
redis-6.2-rc3.tar.gz and redis-6.2.0.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

geo.c  (redis-6.2-rc3):geo.c  (redis-6.2.0)
skipping to change at line 34 skipping to change at line 34
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "geo.h" #include "geo.h"
#include "geohash_helper.h" #include "geohash_helper.h"
#include "debugmacro.h" #include "debugmacro.h"
#include "pqsort.h"
/* Things exported from t_zset.c only for geo.c, since it is the only other /* Things exported from t_zset.c only for geo.c, since it is the only other
* part of Redis that requires close zset introspection. */ * part of Redis that requires close zset introspection. */
unsigned char *zzlFirstInRange(unsigned char *zl, zrangespec *range); unsigned char *zzlFirstInRange(unsigned char *zl, zrangespec *range);
int zslValueLteMax(double value, zrangespec *spec); int zslValueLteMax(double value, zrangespec *spec);
/* ==================================================================== /* ====================================================================
* This file implements the following commands: * This file implements the following commands:
* *
* - geoadd - add coordinates for value to geoset * - geoadd - add coordinates for value to geoset
skipping to change at line 177 skipping to change at line 178
if (conversion) *conversion = to_meters; if (conversion) *conversion = to_meters;
return C_OK; return C_OK;
} }
/* Input Argument Helper. /* Input Argument Helper.
* Extract height and width from the specified three arguments starting at 'argv ' * Extract height and width from the specified three arguments starting at 'argv '
* that should be in the form: <number> <number> <unit>, and return C_OK or C_ER R means success or failure * that should be in the form: <number> <number> <unit>, and return C_OK or C_ER R means success or failure
* *conversions is populated with the coefficient to use in order to convert met ers to the unit.*/ * *conversions is populated with the coefficient to use in order to convert met ers to the unit.*/
int extractBoxOrReply(client *c, robj **argv, double *conversion, int extractBoxOrReply(client *c, robj **argv, double *conversion,
double *height, double *width) { double *width, double *height) {
double h, w; double h, w;
if ((getDoubleFromObjectOrReply(c, argv[0], &h, "need numeric height") != C_ if ((getDoubleFromObjectOrReply(c, argv[0], &w, "need numeric width") != C_O
OK) || K) ||
(getDoubleFromObjectOrReply(c, argv[1], &w, "need numeric width") != C_O (getDoubleFromObjectOrReply(c, argv[1], &h, "need numeric height") != C_
K)) { OK)) {
return C_ERR; return C_ERR;
} }
if (h < 0 || w < 0) { if (h < 0 || w < 0) {
addReplyError(c, "height or width cannot be negative"); addReplyError(c, "height or width cannot be negative");
return C_ERR; return C_ERR;
} }
if (height) *height = h; if (height) *height = h;
if (width) *width = w; if (width) *width = w;
skipping to change at line 226 skipping to change at line 227
int geoAppendIfWithinShape(geoArray *ga, GeoShape *shape, double score, sds memb er) { int geoAppendIfWithinShape(geoArray *ga, GeoShape *shape, double score, sds memb er) {
double distance = 0, xy[2]; double distance = 0, xy[2];
if (!decodeGeohash(score,xy)) return C_ERR; /* Can't decode. */ if (!decodeGeohash(score,xy)) return C_ERR; /* Can't decode. */
/* Note that geohashGetDistanceIfInRadiusWGS84() takes arguments in /* Note that geohashGetDistanceIfInRadiusWGS84() takes arguments in
* reverse order: longitude first, latitude later. */ * reverse order: longitude first, latitude later. */
if (shape->type == CIRCULAR_TYPE) { if (shape->type == CIRCULAR_TYPE) {
if (!geohashGetDistanceIfInRadiusWGS84(shape->xy[0], shape->xy[1], xy[0] , xy[1], if (!geohashGetDistanceIfInRadiusWGS84(shape->xy[0], shape->xy[1], xy[0] , xy[1],
shape->t.radius*shape->conversion , &distance)) return C_ERR; shape->t.radius*shape->conversion , &distance)) return C_ERR;
} else if (shape->type == RECTANGLE_TYPE) { } else if (shape->type == RECTANGLE_TYPE) {
if (!geohashGetDistanceIfInRectangle(shape->bounds, shape->xy[0], shape- if (!geohashGetDistanceIfInRectangle(shape->t.r.width * shape->conversio
>xy[1], n,
xy[0], xy[1], &distance)) return C_ shape->t.r.height * shape->conversi
ERR; on,
shape->xy[0], shape->xy[1], xy[0],
xy[1], &distance))
return C_ERR;
} }
/* Append the new element. */ /* Append the new element. */
geoPoint *gp = geoArrayAppend(ga); geoPoint *gp = geoArrayAppend(ga);
gp->longitude = xy[0]; gp->longitude = xy[0];
gp->latitude = xy[1]; gp->latitude = xy[1];
gp->dist = distance; gp->dist = distance;
gp->member = member; gp->member = member;
gp->score = score; gp->score = score;
return C_OK; return C_OK;
skipping to change at line 637 skipping to change at line 640
if (extractDistanceOrReply(c, c->argv+base_args+i+1, &shape.conv ersion, &shape.t.radius) != C_OK) if (extractDistanceOrReply(c, c->argv+base_args+i+1, &shape.conv ersion, &shape.t.radius) != C_OK)
return; return;
shape.type = CIRCULAR_TYPE; shape.type = CIRCULAR_TYPE;
byradius = 1; byradius = 1;
i += 2; i += 2;
} else if (!strcasecmp(arg, "bybox") && } else if (!strcasecmp(arg, "bybox") &&
(i+3) < remaining && (i+3) < remaining &&
flags & GEOSEARCH && flags & GEOSEARCH &&
!byradius) !byradius)
{ {
if (extractBoxOrReply(c, c->argv+base_args+i+1, &shape.conversio if (extractBoxOrReply(c, c->argv+base_args+i+1, &shape.conversio
n, &shape.t.r.height, n, &shape.t.r.width,
&shape.t.r.width) != C_OK) return; &shape.t.r.height) != C_OK) return;
shape.type = RECTANGLE_TYPE; shape.type = RECTANGLE_TYPE;
bybox = 1; bybox = 1;
i += 3; i += 3;
} else { } else {
addReplyErrorObject(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
} }
skipping to change at line 702 skipping to change at line 705
geoArrayFree(ga); geoArrayFree(ga);
return; return;
} }
long result_length = ga->used; long result_length = ga->used;
long returned_items = (count == 0 || result_length < count) ? long returned_items = (count == 0 || result_length < count) ?
result_length : count; result_length : count;
long option_length = 0; long option_length = 0;
/* Process [optional] requested sorting */ /* Process [optional] requested sorting */
if (sort == SORT_ASC) { if (sort != SORT_NONE) {
qsort(ga->array, result_length, sizeof(geoPoint), sort_gp_asc); int (*sort_gp_callback)(const void *a, const void *b) = NULL;
} else if (sort == SORT_DESC) { if (sort == SORT_ASC) {
qsort(ga->array, result_length, sizeof(geoPoint), sort_gp_desc); sort_gp_callback = sort_gp_asc;
} else if (sort == SORT_DESC) {
sort_gp_callback = sort_gp_desc;
}
if (returned_items == result_length) {
qsort(ga->array, result_length, sizeof(geoPoint), sort_gp_callback);
} else {
pqsort(ga->array, result_length, sizeof(geoPoint), sort_gp_callback,
0, (returned_items - 1));
}
} }
if (storekey == NULL) { if (storekey == NULL) {
/* No target key, return results to user. */ /* No target key, return results to user. */
/* Our options are self-contained nested multibulk replies, so we /* Our options are self-contained nested multibulk replies, so we
* only need to track how many of those nested replies we return. */ * only need to track how many of those nested replies we return. */
if (withdist) if (withdist)
option_length++; option_length++;
 End of changes. 6 change blocks. 
16 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)