35 template <
typename>
class ArrayType,
36 class Cmp = std::less<T>>
41 template <
typename>
class ArrayType,
42 class Cmp = std::less<T>>
46 template <
class ArrayType,
class Cmp>
49 template <
typename ArrayType,
class Cmp>
52 template <
typename ArrayType,
class Cmp>
55 template <
typename T,
class Cmp>
58 template <
typename T,
class Cmp>
61 template <
typename T,
class Cmp>
65 template <
typename T,
class Cmp>
69 std::tuple<DL, DL *, DL>
partition(DL &, Cmp &);
74 template <
class ArrayType>
75 ArrayType
reverse(
const ArrayType &);
77 template <
class SRCL,
class TGTL>
80 template <
typename T,
template <
typename>
class ArrayType,
class Cmp>
91 else if (cmp(a.at(m), k))
98 template <
typename>
class ArrayType,
99 class Cmp = std::less<T>>
103 return binary_search<T, ArrayType, Cmp>(a, k, l, r, cmp);
106 template <
typename T,
107 template <
typename>
class ArrayType,
108 class Cmp = std::less<T>>
112 return binary_search<T, ArrayType, Cmp>(a, k, 0, a.size() - 1, cmp);
115 template <
typename T,
116 template <
typename>
class ArrayType,
117 class Cmp = std::less<T>>
121 return binary_search<T, ArrayType, Cmp>(a, k, cmp);
124 template <
typename T,
template <
typename>
class ArrayType,
class Cmp>
130 while (i <= r and not cmp(k, a.at(i)))
136 template <
typename T,
137 template <
typename>
class ArrayType,
138 class Cmp = std::less<T>>
142 return sequential_search<T, ArrayType, Cmp>(a, k, l, r, cmp);
145 template <
typename T,
146 template <
typename>
class ArrayType,
147 class Cmp = std::less<T>>
150 return sequential_search<T, ArrayType, Cmp>(a, k, 0, a.size() - 1, cmp);
153 template <
typename T,
154 template <
typename>
class ArrayType,
155 class Cmp = std::less<T>>
159 return sequential_search<T, ArrayType, Cmp>(a, k, cmp);
162 template <
class ArrayType,
class Cmp>
165 for (
lint_t i = l + 1; i <= r; ++i)
167 typename ArrayType::DataType data = std::move(a[i]);
171 for ( ; j > l and cmp(data, a[j - 1]); --j)
172 a[j] = std::move(a[j - 1]);
174 a[j] = std::move(data);
178 template <
class ArrayType,
179 class Cmp = std::less<typename ArrayType::DataType>>
inline 182 insertion_sort<ArrayType, Cmp>(a, l, r, cmp);
185 template <
class ArrayType,
class Cmp>
191 template <
class ArrayType,
192 class Cmp = std::less<typename ArrayType::DataType>>
195 insertion_sort<ArrayType, Cmp>(a, size, cmp);
198 template <
class ArrayType,
class Cmp>
204 template <
class ArrayType,
205 class Cmp = std::less<typename ArrayType::DataType>>
208 insertion_sort<ArrayType, Cmp>(a, cmp);
211 template <
typename ArrayType,
class Cmp>
218 lint_t partial_min = cmp(a[l], a[m]) ? l : m;
220 return cmp(a[partial_min], a[r]) ? partial_min : r;
223 template <
typename ArrayType,
class Cmp>
228 std::swap(a[pivot], a[r]);
235 while (cmp(a[++i], a[r]));
237 while (cmp(a[r], a[--j]))
244 std::swap(a[i], a[j]);
247 std::swap(a[i], a[r]);
252 template <
typename ArrayType,
class Cmp>
266 if (pivot - l < r - pivot)
278 template <
class ArrayType,
279 class Cmp = std::less<typename ArrayType::DataType>>
inline 282 quicksort<ArrayType, Cmp>(a, l, r, cmp);
285 template <
class ArrayType,
class Cmp>
291 template <
class ArrayType,
292 class Cmp = std::less<typename ArrayType::DataType>>
295 quicksort<ArrayType, Cmp>(a, size, cmp);
298 template <
class ArrayType,
class Cmp>
304 template <
class ArrayType,
305 class Cmp = std::less<typename ArrayType::DataType>>
306 inline void quicksort(ArrayType & a, Cmp && cmp = Cmp())
308 quicksort<ArrayType, Cmp>(a, cmp);
311 template <
typename T,
class Cmp = std::less<T>>
314 quicksort<FixedArray<T>, Cmp>(a, cmp);
317 template <
typename T,
class Cmp = std::less<T>>
320 quicksort<T, Cmp>(a, cmp);
323 template <
typename T,
class Cmp = std::less<T>>
326 quicksort<DynArray<T>, Cmp>(a, cmp);
329 template <
typename T,
class Cmp = std::less<T>>
332 quicksort<T, Cmp>(a, cmp);
335 template <
typename T,
class Cmp>
342 while (u >= l and cmp(a[i], a[u]))
344 std::swap(a[i], a[u]);
350 template <
typename T,
class Cmp>
353 return sift_up<T, Cmp>(a, l, r, cmp);
356 template <
typename T,
class Cmp>
366 if (cmp(a[c + 1], a[c]))
369 if (not cmp(a[c], a[i]))
372 std::swap(a[c], a[i]);
378 template <
typename T,
class Cmp>
381 return sift_down<T, Cmp>(a, l, r, cmp);
384 template <
typename T,
class Cmp>
385 std::tuple<NodeSLList<T>,
typename NodeSLList<T>::Node *,
NodeSLList<T>>
396 if (cmp(p->get_item(), pivot->get_item()))
402 return std::make_tuple(std::move(ls), pivot, std::move(gs));
405 template <
typename T,
class Cmp>
416 l.
concat(std::get<0>(part));
417 l.
append(std::get<1>(part));
418 l.
concat(std::get<2>(part));
421 template <
typename T,
class Cmp = std::less<T>>
424 quicksort<T, Cmp>(l, cmp);
444 return std::make_tuple(std::move(ls), pivot, std::move(gs));
458 l.
concat(std::get<0>(part));
460 l.
concat(std::get<2>(part));
466 quicksort<Cmp>(l, cmp);
469 template <
typename T,
class Cmp>
489 static_cast<DLNode<T> *
>(r)->get_item());
493 template <
typename T,
class Cmp>
512 return cmp(const_cast<T *>(&a), const_cast<T *>(&b));
516 template <
typename T,
class Cmp>
520 quicksort<KeyCmp<T, Cmp>>(l, key_cmp);
523 template <
typename T,
class Cmp = std::less<T>>
526 quicksort<T, Cmp>(l,
cmp);
529 template <
typename T,
class Cmp>
533 quicksort<KeyCmp<T, Cmp>>(l, key_cmp);
536 template <
typename T,
class Cmp = std::less<T>>
539 quicksort<T, Cmp>(l,
cmp);
542 template <
typename SeqType,
class Cmp = std::less<
typename SeqType::ItemType>>
543 inline SeqType
sort(
const SeqType & s, Cmp & cmp)
546 quicksort<typename SeqType::ItemType, Cmp>(ret_val,
cmp);
550 template <
typename SeqType,
class Cmp = std::less<
typename SeqType::ItemType>>
551 inline SeqType
sort(
const SeqType & s, Cmp && cmp = Cmp())
553 return sort<SeqType, Cmp>(s,
cmp);
556 template <
typename SeqType,
class Cmp = std::less<
typename SeqType::ItemType>>
559 quicksort<typename SeqType::ItemType, Cmp>(s,
cmp);
562 template <
typename SeqType,
class Cmp = std::less<
typename SeqType::ItemType>>
565 inline_sort<SeqType, Cmp>(s,
cmp);
568 template <
class ArrayType>
573 for (
nat_t i = a.size(); i > 0; --i)
574 ret_val.append(a[i - 1]);
579 template <
class SRCL,
class TGTL>
585 ret_val.insert(item);
590 template <
typename T>
593 return reverse<FixedArray<T>>(a);
596 template <
typename T>
599 return reverse<DynArray<T>>(a);
602 template <
typename T>
608 template <
typename T>
Cmp & cmp
Definition: sort.H:472
constexpr lint_t QuicksortThreshold
Definition: types.H:58
void quicksort(ArrayType &, lint_t, lint_t, Cmp &)
Definition: sort.H:253
void insertion_sort(ArrayType &, lint_t, lint_t, Cmp &)
Definition: sort.H:163
ArrayType reverse(const ArrayType &)
Definition: sort.H:569
PtrCmp(Cmp &&_cmp=Cmp())
Definition: sort.H:504
bool operator()(DL *l, DL *r) const
Definition: sort.H:486
bool is_empty() const
Definition: nodesdef.H:153
Definition: nodesdef.H:113
void concat(NodeSLList *l)
Definition: list.H:152
void inline_sort(SeqType &s, Cmp &cmp)
Definition: sort.H:557
bool is_empty() const
Definition: list.H:80
PtrCmp(Cmp &_cmp)
Definition: sort.H:498
lint_t sequential_search(const ArrayType< T > &, const T &, lint_t, lint_t, Cmp &)
Definition: sort.H:125
bool is_unitarian_or_empty() const
Definition: nodesdef.H:158
KeyCmp(Cmp &&_cmp=Cmp())
Definition: sort.H:480
void append(Node *node)
Definition: list.H:106
long long lint_t
Definition: types.H:49
Definition: italgorithms.H:33
lint_t select_pivot(ArrayType &a, lint_t l, lint_t r, Cmp &cmp)
Definition: sort.H:212
Definition: nodesdef.H:415
void sift_up(T *, nat_t, nat_t, Cmp &)
Definition: sort.H:336
SLNode< T > Node
Definition: list.H:38
DL * remove_next()
Definition: nodesdef.H:215
bool is_unitarian_or_empty() const
Definition: list.H:85
Cmp & cmp
Definition: sort.H:496
void sift_down(T *, nat_t, nat_t, Cmp &)
Definition: sort.H:357
unsigned long int nat_t
Definition: types.H:50
SeqType sort(const SeqType &s, Cmp &cmp)
Definition: sort.H:543
lint_t partition(ArrayType &, lint_t, lint_t, Cmp &)
Definition: sort.H:224
lint_t binary_search(const ArrayType< T > &, const T &, lint_t, lint_t, Cmp &)
Definition: sort.H:81
void concat(DL *l)
Definition: nodesdef.H:263
KeyCmp(Cmp &_cmp)
Definition: sort.H:474
Node * remove_first()
Definition: list.H:137
void insert_prev(DL *node)
Definition: nodesdef.H:198