summaryrefslogtreecommitdiff
path: root/src/mongo/db/geo/hash.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/geo/hash.cpp')
-rw-r--r--src/mongo/db/geo/hash.cpp20
1 files changed, 20 insertions, 0 deletions
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]);