#include <lib/sconfig.h>
#include <lib/tl/defop.h>
Include dependency graph for sort.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Defines | |
#define | _TemplateLibrary_SORT_H_ 1 |
#define | TLIB_QUICKSORT_TAIL_CALL_OPTIMIZE 1 |
Internally used by QuickSort(). | |
Functions | |
template<typename T, typename _OP> void | _SortSwap (T *a, size_t i0, size_t i1, T &tmp, const _OP &op) |
Swap indices i0 and i1 in a[] using tmp as a temporary. | |
template<typename T, typename _OP> void | InsertionSortBS (T *a, size_t nelem, const _OP &op=TLDefaultOperators_CDT< T >()) |
Insertion sort template. | |
template<typename T, typename _OP> void | InsertionSort (T *a, size_t nelem, const _OP &op=TLDefaultOperators_CDT< T >()) |
Insertion sort template. | |
template<typename T, typename _OP> void | HeapSort (T *_a, size_t nelem, const _OP &op=TLDefaultOperators_CDT< T >()) |
Heap sort template. | |
template<typename T, typename _OP> void | _QuickSort_Final (T *a, size_t nelem, T &tmp, const _OP &op) |
Internally used by DumbQuickSort() and CleverQuickSort(). | |
template<typename T, typename _OP> void | _DumbQuickSort_R (T *a, size_t nelem, size_t insertion_sort_thresh, const _OP &op) |
Internally used by DumbQuickSort(). | |
template<typename T, typename _OP> void | DumbQuickSort (T *a, size_t nelem, size_t insertion_sort_thresh=16, const _OP &op=TLDefaultOperators_CDT< T >()) |
Quick sort template. | |
template<typename T, typename _OP> void | _CleverQuickSort_R (T *a, size_t nelem, size_t insertion_sort_thresh, const _OP &op) |
template<typename T, typename _OP> void | CleverQuickSort (T *a, size_t nelem, size_t insertion_sort_thresh=16, const _OP &op=TLDefaultOperators_CDT< T >()) |
Quick sort template. |
Definition in file sort.h.
|
|
|
Internally used by QuickSort().
For internal use only. Recursive "clever" quicksort main routine (using median-of-3); do not use directly. Memory consumption is O(log(n)) worst case as the larger subarray is handeled using explicit tail recursion optimization (can be switched on/off using TLIB_QUICKSORT_TAIL_CALL_OPTIMIZE). |
|
Definition at line 323 of file sort.h. References _QuickSort_Final(), _SortSwap(), and Assert. Referenced by CleverQuickSort(). |
|
Internally used by DumbQuickSort().
For internal use only. Recursive (standard/dumb) quicksort main routine; do not use directly. Definition at line 242 of file sort.h. References _QuickSort_Final(), _SortSwap(), and Assert. Referenced by DumbQuickSort(). |
|
Internally used by DumbQuickSort() and CleverQuickSort().
For internal use only. Does the last non-recursive step in sorting. Definition at line 216 of file sort.h. References _SortSwap(), and InsertionSort(). Referenced by _CleverQuickSort_R(), and _DumbQuickSort_R(). |
|
Swap indices i0 and i1 in a[] using tmp as a temporary.
For internal use only.
Definition at line 35 of file sort.h. Referenced by _CleverQuickSort_R(), _DumbQuickSort_R(), _QuickSort_Final(), HeapSort(), and InsertionSortBS(). |
|
Quick sort template.
Do not use on nearly sorted data because this is a dangerous case for quicksort. Instead, use smoothsort or insertion sort in this case.
Runtime: O(n*log(n)) average case and O(n^2) worst case. Definition at line 462 of file sort.h. References _CleverQuickSort_R(). Referenced by X_CleverQuickSort(). |
|
Quick sort template.
Sort order is ascenting.
Runtime: O(n*log(n)) average case and O(n^2) worst case. Definition at line 301 of file sort.h. References _DumbQuickSort_R(). Referenced by X_DumbQuickSort(). |
|
Heap sort template.
Unfortunately, heap sort in the average case is slower than quick sort for several reasons; for example heap sort requires efficient random access to the array elements while quick sort is more local and predictive interfering better with CPU caches. Also, the number of compares and assignments in heap sort is larger than for quick sort in the average case. Do not use on nearly-sorted arrays; for nearly sorted arrays, a heap-sort derived algorithm called smoothsort (Dijkstra) exists, which has O(n) runtime for sorted arrays and a smooth transition to O(n*log(n)) worst case. Sort order is ascenting.
Runtime: O(n*log(n)) average and worst case. Definition at line 147 of file sort.h. References _SortSwap(). Referenced by VM::VMLinker::_MergeNamespaceInfo_Recursive(), and main(). |
|
Insertion sort template.
Use this for nearly sorted data, where elements need to be moved a short distance, e.g. as a "last step" with pre-sorting using quicksort. Sort order is ascenting.
Runtime: O(n^2) for arbitrary arrays; compares and swaps. Definition at line 97 of file sort.h. Referenced by VM::VMLinker::_MergeNamespaceInfo_Recursive(), _QuickSort_Final(), and main(). |
|
Insertion sort template.
Use this for nearly sorted data, i.e. arrays where a few elements are out of order and these few are to be moved a long distance. Sort order is ascenting.
Runtime: O(n^2) for arbitrary arrays: O(n*log(n)) compares and O(n^2) swaps. Definition at line 59 of file sort.h. References _SortSwap(). Referenced by main(). |