19 #ifndef MINLIB_STL_SORT_H_
20 #define MINLIB_STL_SORT_H_
29 void
quick_sort(
T* data,
long low,
long high, TPredicate pred) {
33 const T pivot = data[(low + high) >> 1];
36 while (pred(data[i], pivot)) ++i;
37 while (pred(pivot, data[j])) --j;
53 if (i < high) low = i;
59 void
down_heap(
T* data,
size_t k,
size_t n, TPredicate pred) {
60 const T temp = data[k - 1];
64 if (child < n && pred(data[child - 1], data[child]))
66 if (pred(temp, data[child - 1])) {
67 data[k - 1] = data[child - 1];
78 for (
size_t gap = n/2; gap > 0; gap /= 2) {
79 for (
size_t i = gap; i < n; i += 1) {
82 for (j = i; j >= gap && pred(arr[j - gap], temp); j -= gap) {
83 data[j] = data[j - gap];
93 const size_t num = end - begin;
95 for (
size_t i = 0; i < num; ++i) {
99 while (j > 0 && pred(t, begin[j - 1])) {
100 begin[j] = begin[j - 1];
137 size_t n = end - begin;
138 for (
size_t k = n / 2; k != 0; --k)
142 const T temp = begin[0];
143 begin[0] = begin[n - 1];
157 bool
is_sorted(TIter begin, TIter end, TPredicate pred) {
164 if (pred(*it, *it_prev)) {
176 void
sort(
T* begin,
T* end, TPredicate pred) {
#define MN_TEMPLATE_FULL_DECL_ONE(d1, t1)
Definition: mn_defines.hpp:25
#define MN_TEMPLATE_FULL_DECL_TWO(d1, t1, d2, t2)
Definition: mn_defines.hpp:26
void quick_sort(T *data, long low, long high, TPredicate pred)
Definition: mn_sort.hpp:29
void down_heap(T *data, size_t k, size_t n, TPredicate pred)
Definition: mn_sort.hpp:59
void shell_sort(T *data, size_t n, TPredicate pred)
Definition: mn_sort.hpp:75
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
Definition: mn_allocator_typetraits.hpp:25
void heap_sort(T *begin, T *end, TPredicate pred)
Definition: mn_sort.hpp:135
bool is_sorted(TIter begin, TIter end, TPredicate pred)
Definition: mn_sort.hpp:157
void quick_sort(T *begin, T *end, TPredicate pred)
Definition: mn_sort.hpp:124
void shell_sort(T *begin, T *end, TPredicate pred)
Definition: mn_sort.hpp:112
void insertion_sort(T *begin, T *end, TPredicate pred)
Definition: mn_sort.hpp:92
void sort(T *begin, T *end, TPredicate pred)
Definition: mn_sort.hpp:176
Definition: mn_utils.hpp:181
Definition: mn_utils.hpp:175