1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3 * Contains source code from the article "Radix Sort Revisited".
4 * \file IceRevisitedRadix.h
5 * \author Pierre Terdiman
8 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12 #ifndef __ICERADIXSORT_H__
13 #define __ICERADIXSORT_H__
15 //! Allocate histograms & offsets locally
16 #define RADIX_LOCAL_RAM
20 RADIX_SIGNED
, //!< Input values are signed
21 RADIX_UNSIGNED
, //!< Input values are unsigned
23 RADIX_FORCE_DWORD
= 0x7fffffff
26 class ICECORE_API RadixSort
29 // Constructor/Destructor
33 RadixSort
& Sort(const udword
* input
, udword nb
, RadixHint hint
=RADIX_SIGNED
);
34 RadixSort
& Sort(const float* input
, udword nb
);
36 //! Access to results. mRanks is a list of indices in sorted order, i.e. in the order you may further process your data
37 inline_
const udword
* GetRanks() const { return mRanks
; }
39 //! mIndices2 gets trashed on calling the sort routine, but otherwise you can recycle it the way you want.
40 inline_ udword
* GetRecyclable() const { return mRanks2
; }
43 udword
GetUsedRam() const;
44 //! Returns the total number of calls to the radix sorter.
45 inline_ udword
GetNbTotalCalls() const { return mTotalCalls
; }
46 //! Returns the number of eraly exits due to temporal coherence.
47 inline_ udword
GetNbHits() const { return mNbHits
; }
50 #ifndef RADIX_LOCAL_RAM
51 udword
* mHistogram
; //!< Counters for each byte
52 udword
* mOffset
; //!< Offsets (nearly a cumulative distribution function)
54 udword mCurrentSize
; //!< Current size of the indices list
55 udword
* mRanks
; //!< Two lists, swapped each pass
58 udword mTotalCalls
; //!< Total number of calls to the sort routine
59 udword mNbHits
; //!< Number of early exits due to coherence
61 void CheckResize(udword nb
);
62 bool Resize(udword nb
);
65 #endif // __ICERADIXSORT_H__