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:
The sort order can be specified in the order field:
A sort algorithm can be given in the options field:
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.
Sort an Array of T-type objects The sort is done in place.
Sort nr T-type objects in the Block. The sort is done in place.
Find the k-th largest value. Note: it does a partial sort, thus the data array gets changed..
Swap 2 elements in array.
Quicksort in ascending order.
Heapsort in ascending order.
Insertion sort in ascending order.
Sort a C-array containing nr T-type objects. The resulting index vector gives the sorted indices.
Sort a C-array containing nr T-type objects. The resulting index vector gives the sorted indices.
Swap 2 indices.
Check if 2 values are in ascending order.
When equal, the order is correct if index1
Check if 2 values are in descending order.
When equal, the order is correct if index1
Quicksort in ascending order.
Heapsort in ascending order.
Insertion sort in ascending order.
The following global functions are easier to use than the static
GenSort member functions.
They do an in-place sort of data, thus the data themselves are moved
ending up in the requested order.
The default sorting method is QuickSort, which is the fastest.
However, there are pathological cases where it can be slow.
HeapSort is about twice a slow, but its speed is guaranteed.
InsSort (insertion sort) can be very, very slow, but it is the only
stable sort method (i.e. equal values are kept in their original order).
However,
All sort methods have an option to skip duplicate values. This is the
only case where the returned number of values can be less than the
original number of values.
In-place sort in ascending order using QuickSort.
In-place sort in ascending order using given option.
This option gives the sort method (Sort::QuickSort, Sort::HeapSort
or Sort::InsSort) and/or the option Sort::NoDuplicates.
In-place sort in given order using QuickSort.
The order must be Sort::Ascending or Sort::Descending.
In-place sort in given order using given option.
This option gives the sort method (Sort::QuickSort, Sort::HeapSort,
or Sort::InsSort) and/or the option Sort::NoDuplicates.
The order must be Sort::Ascending or Sort::Descending.
The following global functions easier to use than the static
GenSortIndirect member functions.
They do an indirect sort of data, thus the data themselves are not moved.
Rather an index vector is returned giving the sorted data indices.
The default sorting method is QuickSort, which is the fastest.
However, there are pathological cases where it can be slow.
HeapSort is about twice a slow, but its speed is guaranteed.
InsSort (insertion sort) can be very, very slow.
Unlike the
All sort methods have an option to skip duplicate values. This is the
only case where the returned number of values can be less than the
original number of values.
Indirect sort in ascending order using QuickSort.
Indirect sort in ascending order using given option.
This option gives the sort method (Sort::QuickSort, Sort::HeapSort,
or Sort::InsSort) and/or the option Sort::NoDuplicates.
Indirect sort in given order using QuickSort.
The order must be Sort::Ascending or Sort::Descending.
Indirect sort in given order using given option.
This option gives the sort method (Sort::QuickSort, Sort::HeapSort,
or Sort::InsSort) and/or the option Sort::NoDuplicates.
The order must be Sort::Ascending or Sort::Descending.
static void quickSortDesc (uInt* inx, const T*, Int nr)
Quicksort in descending order.
static void heapSortAsc (uInt* inx, const T*, Int nr)
static void heapSortDesc (uInt* inx, const T*, Int nr)
Heapsort in descending order.
static void heapAscSiftDown (uInt* inx, Int, Int, const T*)
Helper function for ascending heapsort.
static void heapDescSiftDown (uInt* inx, Int, Int, const T*)
Helper function for descending heapsort.
static uInt insSortAsc (uInt* inx, const T*, Int nr, int option)
static uInt insSortDesc (uInt* inx, const T*, Int nr, int option)
Insertion sort in descending order.
static uInt insSortAscDup (uInt* inx, const T*, Int nr)
Insertion sort in ascending order allowing duplicates.
This is also used by quicksort for its last steps.
static uInt insSortDescDup (uInt* inx, const T*, Int nr)
Insertion sort in descending order allowing duplicates.
This is also used by quicksort for its last steps.
static uInt insSortAscNoDup (uInt* inx, const T*, Int nr)
Insertion sort in ascending order allowing no duplicates.
This is also used by the other sort algorithms to skip duplicates.
static uInt insSortDescNoDup (uInt* inx, const T*, Int nr)
Insertion sort in descending order allowing no duplicates.
This is also used by the other sort algorithms to skip duplicates.
Global in-place sort functions (source)
Interface
Description
Member Description
inlineuInt genSort (T* data, uInt nr)
inlineuInt genSort (Array<T>& data)
inlineuInt genSort (Block<T>& data)
inlineuInt genSort (Block<T>& data, uInt nr)
inlineuInt genSort (T* data, uInt nr, int options)
inlineuInt genSort (Array<T>& data, int options)
inlineuInt genSort (Block<T>& data, int options)
inlineuInt genSort (Block<T>& data, uInt nr, int options)
inlineuInt genSort (T* data, uInt nr, Sort::Order order)
inlineuInt genSort (Array<T>& data, Sort::Order order)
inlineuInt genSort (Block<T>& data, Sort::Order order)
inlineuInt genSort (Block<T>& data, uInt nr, Sort::Order order)
inlineuInt genSort (T* data, uInt nr, Sort::Order order, int options)
inlineuInt genSort (Array<T>& data, Sort::Order order, int options)
inlineuInt genSort (Block<T>& data, Sort::Order order, int options)
inlineuInt genSort (Block<T>& data, uInt nr, Sort::Order, int options)
Global indirect sort functions (source)
Interface
Description
Member Description
inlineuInt genSort (Vector<uInt>& indexVector, const T* data, uInt nr)
inlineuInt genSort (Vector<uInt>& indexVector, const Array<T>& data)
inlineuInt genSort (Vector<uInt>& indexVector, const Block<T>& data)
inlineuInt genSort (Vector<uInt>& indexVector, const Block<T>& data, uInt nr)
inlineuInt genSort (Vector<uInt>& indexVector, const T* data, uInt nr, int options)
inlineuInt genSort (Vector<uInt>& indexVector, const Array<T>& data, int options)
inlineuInt genSort (Vector<uInt>& indexVector, const Block<T>& data, int options)
inlineuInt genSort (Vector<uInt>& indexVector, const Block<T>& data, uInt nr, int options)
inlineuInt genSort (Vector<uInt>& indexVector, const T* data, uInt nr, Sort::Order order)
inlineuInt genSort (Vector<uInt>& indexVector, const Array<T>& data, Sort::Order order)
inlineuInt genSort (Vector<uInt>& indexVector, const Block<T>& data, Sort::Order order)
inlineuInt genSort (Vector<uInt>& indexVector, const Block<T>& data, uInt nr, Sort::Order order)
inlineuInt genSort (Vector<uInt>& indexVector, const T* data, uInt nr, Sort::Order order, int options)
inlineuInt genSort (Vector<uInt>& indexVector, Array<T>& data, Sort::Order order, int options)
inlineuInt genSort (Vector<uInt>& indexVector, const Block<T>& data, Sort::Order order, int options)
inlineuInt genSort (Vector<uInt>& indexVector, const Block<T>& data, uInt nr, Sort::Order, int options)