diff --git a/thiersort3.h b/thiersort3.h index afa1d99..e5df720 100644 --- a/thiersort3.h +++ b/thiersort3.h @@ -22,7 +22,7 @@ union th3_fu { typedef union th3_fu th3_fu; /** Tells from the key which bucket it is in. */ -static inline int witch_bucket3(uint32_t key) { +static inline uint32_t witch_bucket3(uint32_t key) { /* This is hackz to misuse int->float converter HEAVILY and IEE for bucketing */ /* https://en.wikipedia.org/wiki/Single-precision_floating-point_format */ @@ -35,7 +35,7 @@ static inline int witch_bucket3(uint32_t key) { th3_fu as; as.f = (float) key; - int witch_base = (key <= 2) ? 0 : (as.u >> 23) - 128; // 0, [127..159] -> [0..31] + uint32_t witch_base = (key <= 2) ? 0 : (as.u >> 23) - 128; // 0, [127..159] -> [0..31] return witch_base * 8 + ((as.u >> (23 - 3)) & 7); // 0..255 /* All below ones were worse, because three-ways 28 bit sorting would just make unnecessary work at cost of some locality */ //return witch_base * 128 + ((as.u >> (23 - 7)) & 127); // 0..4095 @@ -50,6 +50,7 @@ static inline int witch_bucket3(uint32_t key) { * @param arr The array to sort, will contain result afterwards * @param temparr The temporary array with same size * @param n Number of elements in arr and temparr + * @param rstate Create with sch_rand_state rstate = schwab_rand_state(junk_uint32_t); */ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { int bucket[256]; /* Inclusive */ @@ -76,7 +77,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { } /* Prefix sum (like in Magyarsort) */ - int prev = 0; + uint32_t prev = 0; #pragma GCC unroll 4 for (int i = 0; i < 256; i++) { bucket[i] += prev; @@ -107,7 +108,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { #pragma GCC unroll 128 for(int i = 0; i < n; ++i) { uint32_t num = arr[i]; - int witch = witch_bucket3(num); + uint32_t witch = witch_bucket3(num); int offset = (--bucket[witch]); temparr[offset] = num; } @@ -126,7 +127,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { /* Use our specialized threepass */ /* - which does not use up all the bits */ /* - which does not allocate and copy back to arr here */ - int n = end - begin; + uint32_t n = end - begin; uint32_t *a = &(temparr[begin]); uint32_t *buf = &(arr[begin]); threepass_xb(a, buf, n); @@ -138,7 +139,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { #pragma GCC unroll 64 for(int i = 0; i < n; ++i) { uint32_t num = arr[i]; - int witch = witch_bucket3(num); + uint32_t witch = witch_bucket3(num); int offset = (num & (1 << 27)) ? (--bucket[witch]) : (bucket_leftend[witch]++); @@ -160,7 +161,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { /* Use our specialized threepass */ /* - which does not use up all the bits */ /* - which does not allocate and copy back to arr here */ - int n = lend - lbegin; + uint32_t n = lend - lbegin; uint32_t *a = &(temparr[lbegin]); uint32_t *buf = &(arr[lbegin]); threepass_xb(a, buf, n); @@ -171,7 +172,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { /* Use our specialized threepass */ /* - which does not use up all the bits */ /* - which does not allocate and copy back to arr here */ - int n = rend - rbegin; + uint32_t n = rend - rbegin; uint32_t *a = &(temparr[rbegin]); uint32_t *buf = &(arr[rbegin]); threepass_xb(a, buf, n);