56 #define INVALIDATE_RANKS mCurrentSize|=0x80000000 57 #define VALIDATE_RANKS mCurrentSize&=0x7fffffff 58 #define CURRENT_SIZE (mCurrentSize&0x7fffffff) 59 #define INVALID_RANKS (mCurrentSize&0x80000000) 61 #define CHECK_RESIZE(n) \ 62 if(n!=mPreviousSize) \ 64 if(n>mCurrentSize) Resize(n); \ 69 #define CREATE_HISTOGRAMS(type, buffer) \ 71 ZeroMemory(mHistogram, 256*4*sizeof(udword)); \ 74 ubyte* p = (ubyte*)input; \ 75 ubyte* pe = &p[nb*4]; \ 76 udword* h0= &mHistogram[0]; \ 77 udword* h1= &mHistogram[256]; \ 78 udword* h2= &mHistogram[512]; \ 79 udword* h3= &mHistogram[768]; \ 81 bool AlreadySorted = true; \ 86 type* Running = (type*)buffer; \ 87 type PrevVal = *Running; \ 92 type Val = *Running++; \ 94 if(Val<PrevVal) { AlreadySorted = false; break; } \ 99 h0[*p++]++; h1[*p++]++; h2[*p++]++; h3[*p++]++; \ 108 for(udword i=0;i<nb;i++) mRanks[i] = i; \ 115 udword* Indices = mRanks; \ 116 type PrevVal = (type)buffer[*Indices]; \ 121 type Val = (type)buffer[*Indices++]; \ 123 if(Val<PrevVal) { AlreadySorted = false; break; } \ 128 h0[*p++]++; h1[*p++]++; h2[*p++]++; h3[*p++]++; \ 134 if(AlreadySorted) { mNbHits++; return *this; } \ 141 h0[*p++]++; h1[*p++]++; h2[*p++]++; h3[*p++]++; \ 144 #define CHECK_PASS_VALIDITY(pass) \ 146 udword* CurCount = &mHistogram[pass<<8]; \ 149 bool PerformPass = true; \ 160 ubyte UniqueVal = *(((ubyte*)input)+pass); \ 163 if(CurCount[UniqueVal]==nb) PerformPass=false; 172 #ifndef RADIX_LOCAL_RAM 174 mHistogram =
new udword[256*4];
175 mOffset =
new udword[256];
189 #ifndef RADIX_LOCAL_RAM 222 if(nb>CurSize)
Resize(nb);
241 if(!input || !nb || nb&0x80000000)
return *
this;
249 #ifdef RADIX_LOCAL_RAM 265 udword NbNegativeValues = 0;
271 udword* h3= &mHistogram[768];
272 for(
udword i=128;
i<256;
i++) NbNegativeValues += h3[
i];
293 for(
udword i=1;
i<256;
i++) mLink[
i] = mLink[
i-1] + CurCount[
i-1];
301 mLink[0] = &
mRanks2[NbNegativeValues];
303 for(
udword i=1;
i<128;
i++) mLink[
i] = mLink[
i-1] + CurCount[
i-1];
309 for(
udword i=129;
i<256;
i++) mLink[
i] = mLink[
i-1] + CurCount[
i-1];
318 for(
udword i=0;
i<nb;
i++) *mLink[InputBytes[
i<<2]]++ =
i;
325 while(Indices!=IndicesEnd)
329 *mLink[InputBytes[
id<<2]]++ = id;
353 if(!input2 || !nb || nb&0x80000000)
return *
this;
363 #ifdef RADIX_LOCAL_RAM 381 udword NbNegativeValues = 0;
385 udword* h3= &mHistogram[768];
386 for(
udword i=128;
i<256;
i++) NbNegativeValues += h3[
i];
403 for(
udword i=1;
i<256;
i++) mLink[
i] = mLink[
i-1] + CurCount[
i-1];
411 for(
udword i=0;
i<nb;
i++) *mLink[InputBytes[
i<<2]]++ =
i;
418 while(Indices!=IndicesEnd)
422 *mLink[InputBytes[
id<<2]]++ = id;
439 mLink[0] = &
mRanks2[NbNegativeValues];
441 for(
udword i=1;
i<128;
i++) mLink[
i] = mLink[
i-1] + CurCount[
i-1];
447 for(
udword i=0;
i<127;
i++) mLink[254-
i] = mLink[255-
i] + CurCount[255-
i];
449 for(
udword i=128;
i<256;
i++) mLink[
i] += CurCount[
i];
460 if(Radix<128) *mLink[Radix]++ =
i;
461 else *(--mLink[Radix]) =
i;
473 if(Radix<128) *mLink[Radix]++ = mRanks[
i];
474 else *(--mLink[Radix]) = mRanks[
i];
514 #ifndef RADIX_LOCAL_RAM 515 UsedRam += 256*4*
sizeof(
udword);
516 UsedRam += 256*
sizeof(
udword);
void CheckResize(udword nb)
signed int sdword
sizeof(sdword) must be 4
#define null
our own NULL pointer
udword mCurrentSize
Current size of the indices list.
#define DELETEARRAY(x)
Deletes an array.
#define CREATE_HISTOGRAMS(type, buffer)
Input values are unsigned.
udword * mRanks
Two lists, swapped each pass.
unsigned int udword
sizeof(udword) must be 4
#define CHECK_PASS_VALIDITY(pass)
unsigned char ubyte
sizeof(ubyte) must be 1
RadixSort & Sort(const udword *input, udword nb, RadixHint hint=RADIX_SIGNED)
udword mTotalCalls
Total number of calls to the sort routine.
udword GetUsedRam() const