60 #define INVALIDATE_RANKS mCurrentSize |= 0x80000000
61 #define VALIDATE_RANKS mCurrentSize &= 0x7fffffff
62 #define CURRENT_SIZE (mCurrentSize & 0x7fffffff)
63 #define INVALID_RANKS (mCurrentSize & 0x80000000)
65 #define CHECK_RESIZE(n) \
66 if (n != mPreviousSize) { \
67 if (n > mCurrentSize) \
74 #define CREATE_HISTOGRAMS(type, buffer) \
76 ZeroMemory(mHistogram, 256 * 4 * sizeof(udword)); \
79 ubyte* p = (ubyte*)input; \
80 ubyte* pe = &p[nb * 4]; \
81 udword* h0 = &mHistogram[0]; \
82 udword* h1 = &mHistogram[256]; \
83 udword* h2 = &mHistogram[512]; \
84 udword* h3 = &mHistogram[768]; \
86 bool AlreadySorted = true; \
88 if (INVALID_RANKS) { \
90 type* Running = (type*)buffer; \
91 type PrevVal = *Running; \
95 type Val = *Running++; \
97 if (Val < PrevVal) { \
98 AlreadySorted = false; \
114 if (AlreadySorted) { \
116 for (udword i = 0; i < nb; i++) \
122 udword* Indices = mRanks; \
123 type PrevVal = (type)buffer[*Indices]; \
127 type Val = (type)buffer[*Indices++]; \
129 if (Val < PrevVal) { \
130 AlreadySorted = false; \
146 if (AlreadySorted) { \
161 #define CHECK_PASS_VALIDITY(pass) \
163 udword* CurCount = &mHistogram[pass << 8]; \
166 bool PerformPass = true; \
177 ubyte UniqueVal = *(((ubyte*)input) + pass); \
180 if (CurCount[UniqueVal] == nb) \
189 #ifndef RADIX_LOCAL_RAM
191 mHistogram =
new udword[256 * 4];
205 #ifndef RADIX_LOCAL_RAM
273 if (!input || !nb || nb & 0x80000000)
282 #ifdef RADIX_LOCAL_RAM
284 udword mHistogram[256 * 4];
301 udword NbNegativeValues = 0;
309 udword* h3 = &mHistogram[768];
311 NbNegativeValues += h3[
i];
329 mLink[
i] = mLink[
i - 1] + CurCount[
i - 1];
336 mLink[0] = &
mRanks2[NbNegativeValues];
338 mLink[
i] = mLink[
i - 1] + CurCount[
i - 1];
343 mLink[
i] = mLink[
i - 1] + CurCount[
i - 1];
351 *mLink[InputBytes[
i << 2]]++ =
i;
356 while (Indices != IndicesEnd) {
358 *mLink[InputBytes[
id << 2]]++ =
id;
386 if (!input2 || !nb || nb & 0x80000000)
397 #ifdef RADIX_LOCAL_RAM
399 udword mHistogram[256 * 4];
419 udword NbNegativeValues = 0;
425 udword* h3 = &mHistogram[768];
427 NbNegativeValues += h3[
i];
440 mLink[
i] = mLink[
i - 1] + CurCount[
i - 1];
447 *mLink[InputBytes[
i << 2]]++ =
i;
452 while (Indices != IndicesEnd) {
454 *mLink[InputBytes[
id << 2]]++ =
id;
471 mLink[0] = &
mRanks2[NbNegativeValues];
473 mLink[
i] = mLink[
i - 1] + CurCount[
i - 1];
478 mLink[254 -
i] = mLink[255 -
i] + CurCount[255 -
i];
480 mLink[
i] += CurCount[
i];
490 *(--mLink[Radix]) =
i;
498 *mLink[Radix]++ = mRanks[
i];
500 *(--mLink[Radix]) = mRanks[
i];
510 if (UniqueVal >= 128) {
541 #ifndef RADIX_LOCAL_RAM
542 UsedRam += 256 * 4 *
sizeof(
udword);
543 UsedRam += 256 *
sizeof(
udword);
uint16_t *__restrict__ id
signed int sdword
sizeof(sdword) must be 4
udword mTotalCalls
Total number of calls to the sort routine.
udword * RelinquishRanks()
udword mCurrentSize
Current size of the indices list.
udword GetUsedRam() const
#define DELETEARRAY(x)
Deletes an array.
RadixSort & Sort(const udword *input, udword nb, RadixHint hint=RADIX_SIGNED)
static std::string const input
#define CHECK_PASS_VALIDITY(pass)
unsigned int udword
sizeof(udword) must be 4
#define CREATE_HISTOGRAMS(type, buffer)
unsigned char ubyte
sizeof(ubyte) must be 1
void CheckResize(udword nb)
Input values are unsigned.
udword * mRanks
Two lists, swapped each pass.