diff --git a/include/Nazara/Core/Algorithm.hpp b/include/Nazara/Core/Algorithm.hpp index f094c8976..26c9efbcf 100644 --- a/include/Nazara/Core/Algorithm.hpp +++ b/include/Nazara/Core/Algorithm.hpp @@ -8,8 +8,10 @@ #define NAZARA_ALGORITHM_CORE_HPP #include +#include #include +template void NzHashCombine(std::size_t& seed, const T& v); template void NzUnpackTuple(F func, const std::tuple& t); #include diff --git a/include/Nazara/Core/Algorithm.inl b/include/Nazara/Core/Algorithm.inl index 5a8bbeccf..fa1a388ab 100644 --- a/include/Nazara/Core/Algorithm.inl +++ b/include/Nazara/Core/Algorithm.inl @@ -30,6 +30,23 @@ struct NzImplTupleUnpack<0> } }; +// Algorithme venant de CityHash par Google +// http://stackoverflow.com/questions/8513911/how-to-create-a-good-hash-combine-with-64-bit-output-inspired-by-boosthash-co +template +void NzHashCombine(std::size_t& seed, const T& v) +{ + const std::size_t kMul = 0x9ddfea08eb382d69ULL; + + std::hash hasher; + std::size_t a = (hasher(v) ^ seed) * kMul; + a ^= (a >> 47); + + std::size_t b = (seed ^ a) * kMul; + b ^= (b >> 47); + + seed = b * kMul; +} + template void NzUnpackTuple(F func, const std::tuple& t) {