|
static uInt | sort (T *, uInt nr, Sort::Order=Sort::Ascending, int options=0) |
| Sort a C-array containing nr T -type objects. More...
|
|
static uInt | sort (Array< T > &, Sort::Order=Sort::Ascending, int options=0) |
|
static uInt | sort (Block< T > &, uInt nr, Sort::Order=Sort::Ascending, int options=0) |
|
static T | kthLargest (T *data, uInt nr, uInt k) |
| Find the k-th largest value. More...
|
|
static uInt | quickSort (T *, uInt nr, Sort::Order=Sort::Ascending, int options=0) |
| Sort C-array using quicksort. More...
|
|
static uInt | heapSort (T *, uInt nr, Sort::Order=Sort::Ascending, int options=0) |
| Sort C-array using heapsort. More...
|
|
static uInt | insSort (T *, uInt nr, Sort::Order=Sort::Ascending, int options=0) |
| Sort C-array using insertion sort. More...
|
|
static uInt | parSort (T *, uInt nr, Sort::Order=Sort::Ascending, int options=0, int nthread=0) |
| Sort C-array using parallel merge sort (using OpenMP). More...
|
|
static void | swap (T &, T &) |
| Swap 2 elements in array. More...
|
|
static void | reverse (T *data, const T *res, uInt nrrec) |
| Reverse the elements in res and put them into data . More...
|
|
|
static T * | merge (T *data, T *tmp, uInt nrrec, uInt *index, uInt nparts) |
| Thedata buffer is divided in nparts parts. More...
|
|
static void | quickSortAsc (T *, Int, Bool multiThread=False, Int rec_lim=128) |
| Quicksort in ascending order. More...
|
|
static void | heapSortAsc (T *, Int) |
| Heapsort in ascending order. More...
|
|
static void | heapAscSiftDown (Int, Int, T *) |
| Helper function for ascending heapsort. More...
|
|
static uInt | insSortAsc (T *, Int, int option) |
| Insertion sort in ascending order. More...
|
|
static uInt | insSortAscDup (T *, Int) |
| Insertion sort in ascending order allowing duplicates. More...
|
|
static uInt | insSortAscNoDup (T *, Int) |
| Insertion sort in ascending order allowing no duplicates. More...
|
|
template<class T>
class casacore::GenSort< T >
General in-place sort functions
Intended use:
Internal
Review Status
- Reviewed By:
- Friso Olnon
- Date Reviewed:
- 1995/03/16
- Test programs:
- tGenSort
Synopsis
The static member functions of this templated class are highly optimized sort functions. They do an in-place sort of an array of values. The functions are templated, so they can in principle be used with any data type. However, if used with non-builtin data types, their class must provide certain functions (see Template Type Argument Requirements).
If it is impossible or too expensive to define these functions, the Sort class can be used instead. This sorts indirectly using an index array. Instead of the functions mentioned above it requires a comparison routine.
The GenSort
functions can sort:
-
C-arrays of values;
-
Array
s of values – the array can have any shape and the increment can be >1;
-
Block
s of values – there is a special function to sort less elements than the size of the Block
.
The sort order can be specified in the order field:
Sort::Ascending
(default),
Sort::Descending
.
Previously the sort algorithm to use could be given in the options field.
Sort::QuickSort
(default)
- is the fastest. It is about 4-6 times faster than the qsort function on the SUN. No worst case has been found, even not for cases where qsort is terribly slow.
Sort::HeapSort
- is about twice as slow as quicksort. It has the advantage that the worst case is always o(n*log(n)), while quicksort can have hypothetical inputs with o(n*n).
Sort::InsSort
- is o(n*n) for random inputs. It is, however, the only stable sort (i.e. equal values remain in the original order).
However, these options are not used anymore because the sort now always uses a merge sort that is equally fast for random input and much faster for degenerated cases like an already ordered or reversely ordered array. Furthermore, merge sort is always stable and will be parallelized if OpenMP support is enabled giving a 6-fold speedup on 8 cores.
Sort::NoDuplicates
in the options field indicates that duplicate values will be removed (only the first occurrance is kept).
The previous sort functionality is still available through the functions quickSort, heapSort, and insSort.
All the sort functions return the number of values sorted as their function value; when duplicate values have been removed, the number of unique valuess will be returned.
The class also provides a function to find the k-th largest value in an array of values. This uses a stripped-down version of quicksort and is at least 6 times faster than a full quicksort.
Template Type Argument Requirements (T)
-
operator=
to assign when swapping elements
-
operator<
, operator>
and operator==
to compare elements
-
default constructor to allocate a temporary
Definition at line 113 of file GenSort.h.