21 using T = std::remove_reference_t<
decltype(*begin)>;
22 T max_lo{std::numeric_limits<T>::lowest()};
23 T min_hi{std::numeric_limits<T>::max()};
25 for (It p = begin; p != mid; ++p)
26 max_lo = std::max(max_lo, *p);
27 for (It p = mid; p != end; ++p)
28 min_hi = std::min(min_hi, *p);
29 return max_lo <= min_hi;
38 template<
typename T,
typename It>
42 const It the_end = end;
46 const T left = *begin;
47 const T right = *prev(end);
50 const ptrdiff_t adv_lo = right <= pivot;
51 const ptrdiff_t adv_hi = left >= pivot;
56 M_insist(begin == the_end or *begin >= pivot);
62template<
typename Partitioning,
typename It>
63void qsort(It begin, It end, Partitioning p)
66 using std::min, std::max;
68 using std::prev, std::next;
71 while (distance(begin, end) > 2) {
73 auto pm = begin + (end - begin) / 2;
74 bool left_le_mid = *begin <= *pm;
75 bool left_le_right = *begin <= *prev(end);
76 bool mid_le_right = *pm <= *prev(end);
82 swap(*begin, *prev(end));
91 swap(*begin, *prev(end));
98 It mid = p(*begin, next(begin), end);
102 swap(*begin, *prev(mid));
104 if (distance(mid, end) >= 2)
qsort(mid, end, p);
109 if (distance(begin, end) == 2) {
110 if (*begin > *prev(end))
111 swap(*begin, *prev(end));
void qsort(It begin, It end, Partitioning p)
void swap(PlanTableBase< Actual > &first, PlanTableBase< Actual > &second)
bool verify_partition(It begin, It mid, It end)
Verifies that mid splits the range begin to end (exclusive) into two partitions.
Partitions the range begin to end (exclusive) into two partitions using pivot.
It operator()(const T pivot, It begin, It end)