HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_QuickSort.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  */
7 
8 #ifndef __UT_QuickSort__
9 #define __UT_QuickSort__
10 
11 #include "UT_API.h"
12 #include <stddef.h> // For definition of size_t
13 #include "UT_IntArray.h"
14 
15 #if 0
16 typedef int UTcompareFunc(void * /*userdata*/, const void *, const void *);
17 #endif
18 
19 /// This is a bare bones implementation of the Quick Sort,
20 /// so those who don't believe in Radix sort have something to use.
22 {
23 public:
24 
25  /// Sorting methods
26  /// After sorting, use the getIndices() method to get the
27  /// list of indices in sorted order.
28  /// NB: Unlike the UT_RadixSort, the input array IS sorted
29  /// with this quick sort.
30  // @{
31  UT_QuickSort& sort(unsigned int *input, unsigned int nb,
32  int useindex = 1,
33  bool signedvalues=true);
34  UT_QuickSort& sort(fpreal32 *input, unsigned int nb,
35  int useindex = 1);
36  UT_QuickSort& sort(fpreal64 *input, unsigned int nb,
37  int useindex = 1);
38  // @}
39 
40  enum compareType {
43  COMPARE_FLOAT
44  };
45 
46  /// The following sort method is used to sort arbitrary structures.
47  /// The first element of the structure must be an int, unsigned, or
48  /// a float depending on the compareType chosen.
49  UT_QuickSort& sort(void *input, size_t size, unsigned int nb,
50  compareType type);
51 
52 #if 0
53  /// The following sort method is used to sort arbitrary structures.
54  static void sort(void *input, size_t size, unsigned int nb,
55  void *userdata, UTcompareFunc *cmp);
56 #endif
57 
58  /// Return a pointer to the list of indices in sorted order.
59  /// This list is internally stored in myIndices.
60  int* getIndices() { return &myIndices(0); }
61 
62  int operator()(int idx) { return myIndices((unsigned)idx); }
63 
64  /// Reset the internal indices. Note that the list of indices
65  /// in sorted order is kept internally and is checked at the
66  /// beginning of the sort routine to check if the list is
67  /// already sorted.
68  UT_QuickSort& resetIndices() { myIndices.setCapacity(0); return *this; }
69 
70  /// Return the amount of ram used by this particular object.
71  int64 getUsedRam() const
72  { return myIndices.getMemoryUsage(); }
73 protected:
75 
76  /// These are the unsigned, signed, and float sort routines.
77  /// The ones without an index variable don't sort an index array
78  /// along with the main array.
79  // @{
80  static void uisort(unsigned int *input, int *index, int len);
81  static void sisort(int *input, int *index, int len);
82  static void fisort(fpreal32 *input, int *index, int len);
83  static void fisort(fpreal32 *input, int len);
84  static void disort(fpreal64 *input, int *index, int len);
85  static void disort(fpreal64 *input, int len);
86  static void sisort(int *input, int len);
87  static void uisort(unsigned int *input, int len);
88  static void disort(void *input, size_t size, int len, char *tinput);
89  static void fisort(void *input, size_t size, int len, char *tinput);
90  static void sisort(void *input, size_t size, int len, char *tinput);
91  static void uisort(void *input, size_t size, int len, char *tinput);
92  // @}
93 
94  static void urecurse(unsigned int *input, int *index, int len);
95  static void srecurse(int *input, int *index, int len);
96  static void frecurse(fpreal32 *input, int *index, int len);
97  static void drecurse(fpreal64 *input, int *index, int len);
98 
99  static void frecurse(fpreal32 *input, int len);
100  static void drecurse(fpreal64 *input, int len);
101  static void srecurse(int *input, int len);
102  static void urecurse(unsigned int *input, int len);
103 
104  static void drecurse(void *input, size_t size, int len,
105  char *tinput);
106  static void frecurse(void *input, size_t size, int len,
107  char *tinput);
108  static void srecurse(void *input, size_t size, int len,
109  char *tinput);
110  static void urecurse(void *input, size_t size, int len,
111  char *tinput);
112 };
113 
114 #endif
UT_QuickSort & resetIndices()
Definition: UT_QuickSort.h:68
#define UT_API
Definition: UT_API.h:14
float fpreal32
Definition: SYS_Types.h:200
IMATH_HOSTDEVICE constexpr int cmp(T a, T b) IMATH_NOEXCEPT
Definition: ImathFun.h:84
double fpreal64
Definition: SYS_Types.h:201
long long int64
Definition: SYS_Types.h:116
GLsizeiptr size
Definition: glcorearb.h:664
int64 getUsedRam() const
Return the amount of ram used by this particular object.
Definition: UT_QuickSort.h:71
GLuint index
Definition: glcorearb.h:786
int operator()(int idx)
Definition: UT_QuickSort.h:62
UT_IntArray myIndices
Definition: UT_QuickSort.h:74
int * getIndices()
Definition: UT_QuickSort.h:60
type
Definition: core.h:1059
void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7334