예제 #1
0
파일: geo.cpp 프로젝트: harveyaot/ardb
    int Ardb::GeoAdd(const DBID& db, const Slice& key, const GeoAddOptions& options)
    {
        GeoHashRange lat_range, lon_range;
        GeoHashHelper::GetCoordRange(options.coord_type, lat_range, lon_range);
        if (options.x < lon_range.min || options.x > lon_range.max || options.y < lat_range.min
                || options.y > lat_range.max)
        {
            return ERR_INVALID_ARGS;
        }
        GeoPoint point;
        point.x = options.x;
        point.y = options.y;

        if (options.coord_type == GEO_WGS84_TYPE)
        {
            point.x = GeoHashHelper::GetMercatorX(options.x);
            point.y = GeoHashHelper::GetMercatorY(options.y);
            GeoHashHelper::GetCoordRange(GEO_MERCATOR_TYPE, lat_range, lon_range);
        }
        point.attrs = options.attrs;

        GeoHashBits hash;
        geohash_encode(&lat_range, &lon_range, point.y, point.x, 26, &hash);
        GeoHashFix52Bits score = hash.bits;
        ValueData score_value;
        score_value.SetIntValue((int64) score);

        Buffer content;
        point.Encode(content);
        Slice content_value(content.GetRawReadBuffer(), content.ReadableBytes());
        return ZAdd(db, key, score_value, options.value, content_value);
    }
예제 #2
0
	int Ardb::ZAdd(const DBID& db, const Slice& key, double score,
			const Slice& value)
	{
		DoubleArray scores;
		SliceArray svs;
		scores.push_back(score);
		svs.push_back(value);
		return ZAdd(db, key, scores, svs);
	}
예제 #3
0
	int Ardb::ZAddLimit(const DBID& db, const Slice& key, DoubleArray& scores,
			const SliceArray& svs, int setlimit, ValueArray& pops)
	{
		ZSetMetaValue meta;
		GetZSetMetaValue(db, key, meta);
		if (setlimit <= 0)
		{
			setlimit = meta.size + scores.size();
		}
		ZAdd(db, key, scores, svs);
		GetZSetMetaValue(db, key, meta);
		if (meta.size > (uint32) setlimit)
		{
			ZPop(db, key, false, meta.size - setlimit, pops);
		}
		return 0;
	}