tsypko

Untitled

May 9th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. typedef long long ll;
  2. const int size = (1 << 23);
  3. struct hashMap{
  4.     long long H[size + 7] = {};
  5.     int R[size + 7] = {};
  6.     long long mHash(int a, int b){
  7.         return a * 1000000ll + b + 1;
  8.     }
  9.  
  10.     int count(int v, int r){
  11.         ll g = mHash(v, r);
  12.         ll h = g & (size - 1);
  13.         while(1){
  14.             if(H[h] == 0){
  15.                 return 0;
  16.             }
  17.             if(H[h] == g){
  18.                 return 1;
  19.             }
  20.             h++;
  21.             if(h == size){
  22.                 h = 0;
  23.             }
  24.         }
  25.         return 1;
  26.     }
  27.  
  28.     int &operator[](pair<int, int> T){
  29.         ll g = mHash(T.first, T.second);
  30.         ll h = g & (size - 1);
  31.         while(1){
  32.             if(H[h] == 0 || H[h] == g){
  33.                 H[h] = g;
  34.                 return R[h];
  35.             }
  36.             h++;
  37.             if(h == size){
  38.                 h = 0;
  39.             }
  40.         }
  41.     }
  42.    
  43. };
Add Comment
Please, Sign In to add comment