diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2019-08-15 14:48:00 -0400 |
---|---|---|
committer | Gregory Noma <gregory.noma@gmail.com> | 2019-08-15 14:52:10 -0400 |
commit | d49a1faf8c87001cf42f38bec6f92b126008e675 (patch) | |
tree | 3f9657750d44367db1b211f76e3ec4b8537f13d5 /src/mongo/db/geo | |
parent | 575f10c0c89e18537255d3814c817771ff16d127 (diff) | |
download | mongo-d49a1faf8c87001cf42f38bec6f92b126008e675.tar.gz |
SERVER-41730 Make TwoDAccessMethod generate keys using KeyString
Diffstat (limited to 'src/mongo/db/geo')
-rw-r--r-- | src/mongo/db/geo/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/geo/hash.cpp | 20 | ||||
-rw-r--r-- | src/mongo/db/geo/hash.h | 3 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/db/geo/SConscript b/src/mongo/db/geo/SConscript index 0feb1e4888a..fb13309cbfb 100644 --- a/src/mongo/db/geo/SConscript +++ b/src/mongo/db/geo/SConscript @@ -11,6 +11,7 @@ env.Library("geometry", [ "hash.cpp", "r2_region_coverer.cpp" ], LIBDEPS = [ "$BUILD_DIR/mongo/base", "$BUILD_DIR/mongo/db/common", + '$BUILD_DIR/mongo/db/storage/key_string', "$BUILD_DIR/third_party/s2/s2" ]) # Geometry / BSON parsing and wrapping diff --git a/src/mongo/db/geo/hash.cpp b/src/mongo/db/geo/hash.cpp index f8ebed9a7da..6d870ece872 100644 --- a/src/mongo/db/geo/hash.cpp +++ b/src/mongo/db/geo/hash.cpp @@ -498,11 +498,31 @@ static void appendHashToBuilder(long long hash, BSONObjBuilder* builder, const c builder->appendBinData(fieldName, 8, bdtCustom, buf); } +static void appendHashToKeyString(long long hash, KeyString::Builder* ks) { + char buf[8]; +#if MONGO_CONFIG_BYTE_ORDER == MONGO_LITTLE_ENDIAN + // Reverse the order of bytes when copying between BinData and GeoHash. + // GeoHashes are meant to be compared from MSB to LSB, where the first 2 MSB indicate the + // quadrant. + // In BinData, the GeoHash of a 2D index is compared from LSB to MSB, so the bytes should be + // reversed on little-endian systems + copyAndReverse(buf, (char*)&hash); +#else + std::memcpy(buf, reinterpret_cast<char*>(&hash), 8); +#endif + ks->appendBinData(BSONBinData(buf, 8, bdtCustom)); +} + void GeoHash::appendHashMin(BSONObjBuilder* builder, const char* fieldName) const { // The min bound of a GeoHash region has all the unused suffix bits set to 0 appendHashToBuilder(_hash, builder, fieldName); } +void GeoHash::appendHashMin(KeyString::Builder* ks) const { + // The min bound of a GeoHash region has all the unused suffix bits set to 0 + appendHashToKeyString(_hash, ks); +} + void GeoHash::appendHashMax(BSONObjBuilder* builder, const char* fieldName) const { // The max bound of a GeoHash region has all the unused suffix bits set to 1 long long suffixMax = ~(geoBitSets.allX[_bits] | geoBitSets.allY[_bits]); diff --git a/src/mongo/db/geo/hash.h b/src/mongo/db/geo/hash.h index 0133f500e38..bfdca2cdffd 100644 --- a/src/mongo/db/geo/hash.h +++ b/src/mongo/db/geo/hash.h @@ -30,6 +30,7 @@ #pragma once #include "mongo/db/jsobj.h" +#include "mongo/db/storage/key_string.h" #include "mongo/platform/basic.h" namespace mongo { @@ -111,6 +112,8 @@ public: // Append the minimum range of the hash to the builder provided (inclusive) void appendHashMin(BSONObjBuilder* builder, const char* fieldName) const; + // Append the minimum range of the hash to the KeyString provided (inclusive) + void appendHashMin(KeyString::Builder* ks) const; // Append the maximum range of the hash to the builder provided (inclusive) void appendHashMax(BSONObjBuilder* builder, const char* fieldName) const; |