1
/* $Id: sort_func.hpp 13606 2008-06-22 15:21:51Z skidd13 $ */
3
/** @file sort_func.hpp Functions related to sorting operations. */
9
#include "math_func.hpp"
10
#include "mem_func.hpp"
15
* @todo replace the normal qsort with this one
16
* @note Use this sort for irregular sorted data.
18
* @param base Pointer to the first element of the array to be sorted.
19
* @param num Number of elements in the array pointed by base.
20
* @param comparator Function that compares two elements.
21
* @param desc Sort descending.
24
static FORCEINLINE void QSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
28
qsort(base, num, sizeof(T), (int (CDECL *)(const void *, const void *))comparator);
30
if (desc) MemReverseT(base, num);
34
* Type safe Gnome Sort.
36
* This is a slightly modifyied Gnome search. The basic
37
* Gnome search trys to sort already sorted list parts.
38
* The modification skips these.
40
* @note Use this sort for presorted / regular sorted data.
42
* @param base Pointer to the first element of the array to be sorted.
43
* @param num Number of elements in the array pointed by base.
44
* @param comparator Function that compares two elements.
45
* @param desc Sort descending.
48
static inline void GSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
53
assert(comparator != NULL);
60
const int diff = comparator(a, b);
61
if ((!desc && diff <= 0) || (desc && diff >= 0)) {
63
/* Jump back to the last direction switch point */
76
if (a == base) continue;
85
#endif /* SORT_FUNC_HPP */