diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-11-23 16:50:29 -0500 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2016-03-02 16:41:53 -0500 |
commit | cdd95deb1b5ebb8dbf9ec76a96ebcf511ba3a14e (patch) | |
tree | c071c528787e090fe8095d417272eea71a276e39 /src/mongo/base/string_data.cpp | |
parent | 9405fa9e1e0d5f24cb0bc210969cb35de84ae8fc (diff) | |
download | mongo-cdd95deb1b5ebb8dbf9ec76a96ebcf511ba3a14e.tar.gz |
SERVER-21828 Murmurhash for bigendian
Make murmurhash output the same on big endian architectures as on little
endian.
Diffstat (limited to 'src/mongo/base/string_data.cpp')
-rw-r--r-- | src/mongo/base/string_data.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/mongo/base/string_data.cpp b/src/mongo/base/string_data.cpp index f00b185fc29..df7374fcf93 100644 --- a/src/mongo/base/string_data.cpp +++ b/src/mongo/base/string_data.cpp @@ -30,6 +30,9 @@ #include <ostream> #include <third_party/murmurhash3/MurmurHash3.h> +#include "mongo/base/data_type_endian.h" +#include "mongo/base/data_view.h" + namespace mongo { namespace { @@ -39,16 +42,16 @@ size_t murmur3(StringData str); template <> size_t murmur3<4>(StringData str) { - uint32_t hash; + char hash[4]; MurmurHash3_x86_32(str.rawData(), str.size(), 0, &hash); - return hash; + return ConstDataView(hash).read<LittleEndian<std::uint32_t>>(); } template <> size_t murmur3<8>(StringData str) { - uint64_t hash[2]; + char hash[16]; MurmurHash3_x64_128(str.rawData(), str.size(), 0, hash); - return static_cast<size_t>(hash[0]); + return static_cast<size_t>(ConstDataView(hash).read<LittleEndian<std::uint64_t>>()); } } // namespace |