Guest User

Untitled

a guest
Mar 16th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. template <typename T>
  2. void hash_combine(std::size_t& seed, const T& v)
  3. {
  4.     std::hash<T> hasher;
  5.     seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
  6. }
  7.  
  8. namespace std
  9. {
  10.  
  11.     template<>
  12.     struct hash<KeyType>
  13.     {
  14.         size_t operator() (const KeyType& kt)
  15.         {
  16.             size_t seed = 0;
  17.             hash_combine(seed, kt.x);
  18.             hash_combine(seed, kt.y);
  19.             hash_combine(seed, kt.z);
  20.             return seed;
  21.         }
  22.     };
  23. }
Advertisement
Add Comment
Please, Sign In to add comment