12template <
typename Iterator,
typename Compare>
16 JPH_ASSERT(inFirst != inMiddle && inMiddle != inLast);
18 if (inCompare(*inMiddle, *inFirst))
19 swap(*inFirst, *inMiddle);
21 if (inCompare(*inLast, *inFirst))
22 swap(*inFirst, *inLast);
24 if (inCompare(*inLast, *inMiddle))
25 swap(*inMiddle, *inLast);
29template <
typename Iterator,
typename Compare>
30inline void QuickSortNinther(Iterator inFirst, Iterator inMiddle, Iterator inLast, Compare inCompare)
33 auto diff = (inLast - inFirst) >> 3;
34 auto two_diff = diff << 1;
37 Iterator mid1 = inFirst + diff;
44 Iterator mid3 = inLast - diff;
52template <
typename Iterator,
typename Compare>
53inline void QuickSort(Iterator inBegin, Iterator inEnd, Compare inCompare)
61 auto num_elements = inEnd - inBegin;
66 if (num_elements <= 32)
73 Iterator pivot_iterator = inBegin + ((num_elements - 1) >> 1);
75 auto pivot = *pivot_iterator;
84 while (inCompare(*i, pivot))
90 while (inCompare(pivot, *j));
110 if (j - inBegin < inEnd - j)
130template <
typename Iterator>
#define JPH_NAMESPACE_END
Definition: Core.h:378
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
JPH_NAMESPACE_BEGIN void InsertionSort(Iterator inBegin, Iterator inEnd, Compare inCompare)
Implementation of the insertion sort algorithm.
Definition: InsertionSort.h:11
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
void QuickSort(Iterator inBegin, Iterator inEnd, Compare inCompare)
Implementation of the quick sort algorithm. The STL version implementation is not consistent across p...
Definition: QuickSort.h:53
void QuickSortNinther(Iterator inFirst, Iterator inMiddle, Iterator inLast, Compare inCompare)
Helper function for QuickSort using the Ninther method, will move the pivot element to inMiddle.
Definition: QuickSort.h:30
JPH_NAMESPACE_BEGIN void QuickSortMedianOfThree(Iterator inFirst, Iterator inMiddle, Iterator inLast, Compare inCompare)
Helper function for QuickSort, will move the pivot element to inMiddle.
Definition: QuickSort.h:13