HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_RadixSort.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Utility Library (C++)
7  *
8  * COMMENTS:
9  * This is a class which implements a radix sort, but for 4 byte
10  * integer and (IEEE) floating point numbers. The sort algorithms
11  * take endianness into consideration so the user does not need to
12  * worry about it.
13  *
14  * This class is based off of the comments on Pierre Terdiman's
15  * web page "Radix Sort Revisted" as well as the provided source
16  * code.
17  *
18  * http://www.codercorner.com/RadixSortRevisited.htm
19  *
20  * Original code:
21  * Source code for "Radix Sort Revisited"
22  * (C) 2000, Pierre Terdiman (p.terdiman@wanadoo.fr)
23  */
24 
25 #ifndef __UT_RadixSort_h__
26 #define __UT_RadixSort_h__
27 
28 #include "UT_API.h"
29 #include "UT_NonCopyable.h"
30 #include <SYS/SYS_Types.h>
31 
33 {
34 public:
35  UT_RadixSort();
36  ~UT_RadixSort();
37 
39 
40  // Sorting methods
41  // After sorting, use the getIndices() method to get the
42  // list of indices in sorted order.
43  // NB: The input array is NOT sorted by this routine,
44  // you must use the index array to figure out where
45  // each element belongs.
46  UT_RadixSort& sort(uint *input, uint nb,
47  bool signedvalues=true);
48  UT_RadixSort& sort(float *input, uint nb);
49 
50  // Return a pointer to the list of indices in sorted order.
51  // This list is internally stored in myIndices.
52  unsigned int *getIndices() { return myIndices; }
53 
54  // Reset the internal indices. Note that the list of indices
55  // in sorted order is kept internally and is checked at the
56  // beginning of the sort routine to check if the list is
57  // already sorted.
58  UT_RadixSort &resetIndices();
59 
60  // Return the amount of ram used by this particular object.
61  uint getUsedRam();
62 private:
63  void resizeIndices(unsigned int new_size);
64 
65  uint *myHistogram; // Counters for each byte
66  uint *myOffset; // Offsets (nearly a cumulative
67  // distribution function)
68 
69  uint myCurrentSize; // Current size of the indices list
70 
71  uint *myIndices; // Two lists, swapped each pass
72  uint *myIndices2;
73 };
74 
75 #endif // __UT_RadixSort_h__
#define UT_API
Definition: UT_API.h:14
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
unsigned int * getIndices()
Definition: UT_RadixSort.h:52
unsigned int uint
Definition: SYS_Types.h:45
void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7334