00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Ondrej Kos 00008 * Side Effects Software Inc. 00009 * 477 Richmond Street West 00010 * Toronto, Ontario, M5V 3E7 00011 * Canada 00012 * 416-504-9876 00013 * 00014 * NAME: Utility Library (C++) 00015 * 00016 * COMMENTS: 00017 * This is a class which implements a radix sort, but for 4 byte 00018 * integer and (IEEE) floating point numbers. The sort algorithms 00019 * take endianness into consideration so the user does not need to 00020 * worry about it. 00021 * 00022 * This class is based off of the comments on Pierre Terdiman's 00023 * web page "Radix Sort Revisted" as well as the provided source 00024 * code. 00025 * 00026 * http://www.codercorner.com/RadixSortRevisited.htm 00027 * 00028 * Original code: 00029 * Source code for "Radix Sort Revisited" 00030 * (C) 2000, Pierre Terdiman (p.terdiman@wanadoo.fr) 00031 */ 00032 00033 #ifndef __UT_RadixSort_h__ 00034 #define __UT_RadixSort_h__ 00035 00036 #include "UT_API.h" 00037 #include <SYS/SYS_Types.h> 00038 00039 class UT_API UT_RadixSort 00040 { 00041 public: 00042 UT_RadixSort(); 00043 ~UT_RadixSort(); 00044 00045 // Sorting methods 00046 // After sorting, use the getIndices() method to get the 00047 // list of indices in sorted order. 00048 // NB: The input array is NOT sorted by this routine, 00049 // you must use the index array to figure out where 00050 // each element belongs. 00051 UT_RadixSort& sort(uint *input, uint nb, 00052 bool signedvalues=true); 00053 UT_RadixSort& sort(float *input, uint nb); 00054 00055 // Return a pointer to the list of indices in sorted order. 00056 // This list is internally stored in myIndices. 00057 unsigned int *getIndices() { return myIndices; } 00058 00059 // Reset the internal indices. Note that the list of indices 00060 // in sorted order is kept internally and is checked at the 00061 // beginning of the sort routine to check if the list is 00062 // already sorted. 00063 UT_RadixSort &resetIndices(); 00064 00065 // Return the amount of ram used by this particular object. 00066 uint getUsedRam(); 00067 private: 00068 void resizeIndices(unsigned int new_size); 00069 00070 uint *myHistogram; // Counters for each byte 00071 uint *myOffset; // Offsets (nearly a cumulative 00072 // distribution function) 00073 00074 uint myCurrentSize; // Current size of the indices list 00075 00076 uint *myIndices; // Two lists, swapped each pass 00077 uint *myIndices2; 00078 }; 00079 00080 #endif // __UT_RadixSort_h__
1.5.9