C++0x adds hash<...>(...)
.
I could not find a hash_combine
function though, as presented in boost. What is the cleanest way to implement something like this? Perhaps, using C++0x xor_combine
?
Calls to hash_combine incrementally build the hash from the different members of point, it can be repeatedly called for any number of elements. It calls hash_value on the supplied element, and combines it with the seed. Full code for this example is at /libs/functional/hash/examples/point. cpp. Note.
That is, XOR is most suitable for the purpose of combining hashes because we want to capture entropy from both a and b. Here is a paper that explains that combining hashes securely where each function is called only once is not possible without outputting less bits than the sum of number of bits in each hash value.
Well, just do it like the boost guys did it:
template <class T> inline void hash_combine(std::size_t& seed, const T& v) { std::hash<T> hasher; seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With