Alex_tz307

UMAP pair + Custom Hash

Feb 26th, 2021 (edited)
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. struct pair_hash {
  2.     template<class T1, class T2>
  3.     size_t operator() (const pair<T1, T2> &p) const {
  4.         return hash<T1>()(p.first)^hash<T2>()(p.second);
  5.     }
  6. };
  7. unordered_map<pair<int,int>,int,pair_hash> match;
  8.  
  9. struct custom_hash {
  10.     static uint64_t splitmix64 (uint64_t x) {
  11.         x += 0x9e3779b97f4a7c15;
  12.         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
  13.         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
  14.         return x ^ (x >> 31);
  15.     }
  16.  
  17.     size_t operator () (uint64_t x) const {
  18.         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  19.         return splitmix64(x + FIXED_RANDOM);
  20.     }
  21. };
  22. unordered_map<int,int,custom_hash> Map;
Add Comment
Please, Sign In to add comment