Added HashCombine function
Former-commit-id: 852deae33143138f2841e226690bfef94d3ba2b9
This commit is contained in:
parent
cadeae5e21
commit
96a5bc950c
|
|
@ -8,8 +8,10 @@
|
|||
#define NAZARA_ALGORITHM_CORE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
|
||||
template<typename T> void NzHashCombine(std::size_t& seed, const T& v);
|
||||
template<typename F, typename... ArgsT> void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t);
|
||||
|
||||
#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<typename T>
|
||||
void NzHashCombine(std::size_t& seed, const T& v)
|
||||
{
|
||||
const std::size_t kMul = 0x9ddfea08eb382d69ULL;
|
||||
|
||||
std::hash<T> 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<typename F, typename... ArgsT>
|
||||
void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue