From: Lucian Grijincu Date: Mon, 26 Oct 2015 22:50:26 +0000 (-0700) Subject: folly: hash: specialize hash_combine_generic by size_t size X-Git-Tag: deprecate-dynamic-initializer~294 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=59527d6ae3453d12190f38762637c0fd19b6abd7;p=folly.git folly: hash: specialize hash_combine_generic by size_t size Reviewed By: yangliu Differential Revision: D2578043 fb-gh-sync-id: cec8f21219655a495b99d0b6b99f0925615bc068 --- diff --git a/folly/Hash.h b/folly/Hash.h index 194017fa..7e44fbb2 100644 --- a/folly/Hash.h +++ b/folly/Hash.h @@ -17,11 +17,12 @@ #ifndef FOLLY_BASE_HASH_H_ #define FOLLY_BASE_HASH_H_ +#include #include -#include #include -#include #include +#include +#include #include #include @@ -73,6 +74,8 @@ uint64_t hash_range(Iter begin, return hash; } +inline uint32_t twang_32from64(uint64_t key); + template size_t hash_combine_generic(const T& t, const Ts&... ts) { size_t seed = Hasher::hash(t); @@ -80,7 +83,11 @@ size_t hash_combine_generic(const T& t, const Ts&... ts) { return seed; } size_t remainder = hash_combine_generic(ts...); - return hash_128_to_64(seed, remainder); + /* static */ if (sizeof(size_t) == sizeof(uint32_t)) { + return twang_32from64((uint64_t(seed) << 32) | remainder); + } else { + return static_cast(hash_128_to_64(seed, remainder)); + } } // Simply uses std::hash to hash. Note that std::hash is not guaranteed @@ -368,19 +375,20 @@ template<> struct hasher { template<> struct hasher { size_t operator()(int64_t key) const { - return hash::twang_mix64(uint64_t(key)); + return static_cast(hash::twang_mix64(uint64_t(key))); } }; template<> struct hasher { size_t operator()(uint64_t key) const { - return hash::twang_mix64(key); + return static_cast(hash::twang_mix64(key)); } }; template<> struct hasher { size_t operator()(const std::string& key) const { - return hash::SpookyHashV2::Hash64(key.data(), key.size(), 0); + return static_cast( + hash::SpookyHashV2::Hash64(key.data(), key.size(), 0)); } };