SHARE
TWEET

Untitled

a guest May 22nd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int MSK_SZ = 16;
  2. const int MSK = (1 << MSK_SZ) - 1;
  3.  
  4. const int MAX_TEMP_SIZE = (int)4e7;
  5.  
  6. int sz[MSK + 1], ptr[MSK + 1];
  7. int temp[MAX_TEMP_SIZE];
  8.  
  9. inline void radix(int* arr, int n)
  10. {
  11.     for(int p = 0; p < (int)((8 * sizeof(int)) / MSK_SZ); ++p)
  12.     {
  13.         /*for(int i = 0; i <= MSK; ++i)
  14.             sz[i] = 0;*/
  15.  
  16.         memset(sz, 0, sizeof(sz));
  17.         memcpy(temp, arr, sizeof(int) * n);
  18.  
  19.         for(int i = 0; i < n; ++i)
  20.         {
  21.             int value = arr[i];
  22.             int bucket = (value >> (p * MSK_SZ)) & MSK;
  23.  
  24.             ++sz[bucket];
  25.             //temp[i] = value;
  26.         }
  27.  
  28.         ptr[0] = 0;
  29.  
  30.         for(int bucket = 1; bucket <= MSK; ++bucket)
  31.             ptr[bucket] = ptr[bucket - 1] + sz[bucket - 1];
  32.  
  33.         for(int i = 0; i < n; ++i)
  34.         {
  35.             int value = temp[i];
  36.             int bucket = (value >> (p * MSK_SZ)) & MSK;
  37.  
  38.             arr[ptr[bucket]] = value;
  39.             ++ptr[bucket];
  40.         }
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top