If you want hash_combine to hash 2 64-bit values into one, and you don't need a new hash function for strings, you can just pick up a tiny bit of code from CityHash, something like this (assuming size_t is 64- unsigned bit integer, add your favorite preprocessor bit or pattern trick to check this):
template <class T> inline void hash_combine(std::size_t& seed, const T& v) { std::hash<T> hasher; const std::size_t kMul = 0x9ddfea08eb382d69ULL; std::size_t a = (hasher(v) ^ seed) * kMul; a ^= (a >> 47); std::size_t b = (seed ^ a) * kMul; b ^= (b >> 47); seed = b * kMul; }
(I think that playing this snippet here and elsewhere is fine, because it is not an “essential part” of CityHash code, but please check the sources and CityHash license agreement to decide for yourself)
Scott Howlett
source share