10template <
typename Iterator>
12 while ((first != last) && (first != --last)) {
13 swap(*first++, *last);
17template <
typename Iterator>
23 Iterator max_iter = first;
26 while (first != last) {
27 if (*max_iter < *first) {
36template <
typename Iterator,
typename Compare>
42 Iterator max_iter = first;
45 while (first != last) {
46 if (comp(*max_iter, *first)) {
55template <
typename Iterator>
61 Iterator min_iter = first;
64 while (first != last) {
65 if (*first < *min_iter) {
74template <
typename Iterator,
typename Compare>
80 Iterator min_iter = first;
83 while (first != last) {
84 if (comp(*first, *min_iter)) {
95template <
typename Iterator1,
typename Iterator2>
97 while (first1 != last1) {
98 if (*first1 != *first2) {
107template <
typename Iterator1,
typename Iterator2,
typename BinaryPredicate>
108bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, BinaryPredicate pred)
FL_NOEXCEPT {
109 while (first1 != last1) {
110 if (!pred(*first1, *first2)) {
119template <
typename Iterator1,
typename Iterator2>
120bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
FL_NOEXCEPT {
121 while (first1 != last1 && first2 != last2) {
122 if (*first1 != *first2) {
128 return first1 == last1 && first2 == last2;
131template <
typename Iterator1,
typename Iterator2,
typename BinaryPredicate>
132bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, BinaryPredicate pred)
FL_NOEXCEPT {
133 while (first1 != last1 && first2 != last2) {
134 if (!pred(*first1, *first2)) {
140 return first1 == last1 && first2 == last2;
145template <
typename Iterator1,
typename Iterator2>
147 while (first1 != last1 && first2 != last2) {
148 if (*first1 < *first2) {
151 if (*first2 < *first1) {
160 return (first1 == last1) && (first2 != last2);
164template <
typename Iterator1,
typename Iterator2,
typename Compare>
166 while (first1 != last1 && first2 != last2) {
167 if (comp(*first1, *first2)) {
170 if (comp(*first2, *first1)) {
179 return (first1 == last1) && (first2 != last2);
182template <
typename Container1,
typename Container2>
184 fl::size size1 = c1.size();
185 fl::size size2 = c2.size();
186 if (size1 != size2) {
189 return equal(c1.begin(), c1.end(), c2.begin(), c2.end());
192template <
typename Container1,
typename Container2,
typename BinaryPredicate>
194 fl::size size1 = c1.size();
195 fl::size size2 = c2.size();
196 if (size1 != size2) {
199 return equal(c1.begin(), c1.end(), c2.begin(), c2.end(), pred);
203template <
typename Iterator,
typename T>
205 while (first != last) {
211template <
typename Iterator,
typename T>
213 while (first != last) {
214 if (*first ==
value) {
222template <
typename Iterator,
typename UnaryPredicate>
224 while (first != last) {
233template <
typename Iterator,
typename UnaryPredicate>
235 while (first != last) {
244template <
typename Iterator,
typename T>
246 while (first != last) {
247 if (*first == old_value) {
254template <
typename Iterator,
typename UnaryPredicate,
typename T>
256 while (first != last) {
264template <
typename Iterator,
typename T>
267 while (first != last) {
268 if (!(*first ==
value)) {
279template <
typename Iterator,
typename UnaryPredicate>
282 while (first != last) {
297template <
typename Iterator,
typename Compare>
299 if (first == last)
return;
301 for (Iterator i = first + 1; i != last; ++i) {
305 while (j != first && comp(
value, *(j - 1))) {
315template <
typename Iterator,
typename Compare>
317 if (comp(*middle, *first)) {
318 if (comp(*last, *middle)) {
320 }
else if (comp(*last, *first)) {
326 if (comp(*last, *first)) {
328 }
else if (comp(*last, *middle)) {
337template <
typename Iterator,
typename Compare>
339 Iterator middle = first + (last - first) / 2;
343 swap(*pivot_iter, *(last - 1));
344 Iterator pivot = last - 1;
347 for (Iterator j = first; j != pivot; ++j) {
348 if (comp(*j, *pivot)) {
359template <
typename Iterator,
typename Compare>
361 Iterator root = start;
363 while (root - first <= (
end - first - 2) / 2) {
364 Iterator child = first + 2 * (root - first) + 1;
365 Iterator swap_iter = root;
367 if (comp(*swap_iter, *child)) {
371 if (child + 1 <=
end && comp(*swap_iter, *(child + 1))) {
372 swap_iter = child + 1;
375 if (swap_iter == root) {
378 swap(*root, *swap_iter);
384template <
typename Iterator,
typename Compare>
386 Iterator start = first + (last - first - 2) / 2;
390 if (start == first) {
397template <
typename Iterator,
typename Compare>
401 Iterator
end = last - 1;
402 while (
end > first) {
410template <
typename Iterator,
typename Compare>
412 if (last - first <= 16) {
417 Iterator pivot =
partition(first, last, comp);
423template <
typename Iterator>
425 if (first == middle || middle == last) {
429 Iterator next = middle;
430 while (first != next) {
431 swap(*first++, *next++);
434 }
else if (first == middle) {
441template <
typename Iterator,
typename T,
typename Compare>
443 auto count = last - first;
445 auto step = count / 2;
446 Iterator it = first +
step;
447 if (comp(*it,
value)) {
458template <
typename Iterator,
typename Compare>
461 if (first == middle || middle == last) {
466 auto left_size = middle - first;
467 auto right_size = last - middle;
468 if (left_size + right_size <= 32) {
470 Iterator left = first;
471 Iterator right = middle;
473 while (left < middle && right < last) {
474 if (!comp(*right, *left)) {
480 Iterator shift_end = right;
481 Iterator shift_start = left;
484 while (shift_end > shift_start) {
485 *shift_end =
fl::move(*(shift_end - 1));
499 if (left_size == 0 || right_size == 0) {
503 if (left_size == 1) {
510 if (right_size == 1) {
518 Iterator left_mid = first + left_size / 2;
525 Iterator new_middle = left_mid + (right_mid - middle);
533template <
typename Iterator,
typename Compare>
535 auto size = last - first;
541 Iterator middle = first + size / 2;
550template <
typename Iterator,
typename T,
typename Compare>
555template <
typename Iterator,
typename T>
559 [](
const value_type& a,
const T& b) {
return a < b; });
563template <
typename Iterator,
typename Compare>
565 if (first == last || first + 1 == last) {
573template <
typename Iterator>
577 sort(first, last, [](
const value_type& a,
const value_type& b) {
return a < b; });
581template <
typename Iterator,
typename Compare>
583 if (first == last || first + 1 == last) {
591template <
typename Iterator>
595 stable_sort(first, last, [](
const value_type& a,
const value_type& b) {
return a < b; });
611template <
typename Iterator,
typename Compare>
613 if (first == last || first + 1 == last) {
619template <
typename Iterator>
623 [](
const value_type& a,
const value_type& b) {
return a < b; });
627template <
typename Iterator,
typename RandomGenerator>
633 auto n = last - first;
634 for (
auto i = n - 1; i > 0; --i) {
636 auto j = g() % (i + 1);
639 swap(*(first + i), *(first + j));
644template <
typename Iterator>
650 auto n = last - first;
651 for (
auto i = n - 1; i > 0; --i) {
653 auto j = rng(
static_cast<u32
>(i + 1));
656 swap(*(first + i), *(first + j));
661template <
typename Iterator>
A random number generator class that wraps FastLED's random functions.
void rotate_impl(Iterator first, Iterator middle, Iterator last) FL_NOEXCEPT
void quicksort_impl(Iterator first, Iterator last, Compare comp) FL_NOEXCEPT
void heapify(Iterator first, Iterator last, Compare comp) FL_NOEXCEPT
void sift_down(Iterator first, Iterator start, Iterator end, Compare comp) FL_NOEXCEPT
void mergesort_impl(Iterator first, Iterator last, Compare comp) FL_NOEXCEPT
void merge_inplace(Iterator first, Iterator middle, Iterator last, Compare comp) FL_NOEXCEPT
Iterator median_of_three(Iterator first, Iterator middle, Iterator last, Compare comp) FL_NOEXCEPT
Iterator partition(Iterator first, Iterator last, Compare comp) FL_NOEXCEPT
void heap_sort(Iterator first, Iterator last, Compare comp) FL_NOEXCEPT
Iterator lower_bound_impl(Iterator first, Iterator last, const T &value, Compare comp) FL_NOEXCEPT
void insertion_sort(Iterator first, Iterator last, Compare comp) FL_NOEXCEPT
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
Iterator find(Iterator first, Iterator last, const T &value) FL_NOEXCEPT
constexpr int type_rank< T >::value
Iterator find_if(Iterator first, Iterator last, UnaryPredicate pred) FL_NOEXCEPT
constexpr T * end(T(&array)[N]) FL_NOEXCEPT
bool lexicographical_compare(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) FL_NOEXCEPT
bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2) FL_NOEXCEPT
Iterator min_element(Iterator first, Iterator last) FL_NOEXCEPT
void replace_if(Iterator first, Iterator last, UnaryPredicate pred, const T &new_value) FL_NOEXCEPT
void swap(array< T, N > &lhs, array< T, N > &rhs) FL_NOEXCEPT
void stable_sort(Iterator first, Iterator last, Compare comp) FL_NOEXCEPT
math::random & default_random()
Global default random number generator instance.
expected< T, E > result
Alias for expected (Rust-style naming)
Iterator remove_if(Iterator first, Iterator last, UnaryPredicate pred) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type step(T edge, T x) FL_NOEXCEPT
void sort(Iterator first, Iterator last, Compare comp) FL_NOEXCEPT
void sort_small(Iterator first, Iterator last, Compare comp) FL_NOEXCEPT
Iterator lower_bound(Iterator first, Iterator last, const T &value, Compare comp) FL_NOEXCEPT
void shuffle(Iterator first, Iterator last, RandomGenerator &g) FL_NOEXCEPT
void fill(Iterator first, Iterator last, const T &value) FL_NOEXCEPT
Iterator max_element(Iterator first, Iterator last) FL_NOEXCEPT
void reverse(Iterator first, Iterator last) FL_NOEXCEPT
void replace(Iterator first, Iterator last, const T &old_value, const T &new_value) FL_NOEXCEPT
Iterator remove(Iterator first, Iterator last, const T &value) FL_NOEXCEPT
Iterator find_if_not(Iterator first, Iterator last, UnaryPredicate pred) FL_NOEXCEPT
bool equal_container(const Container1 &c1, const Container2 &c2) FL_NOEXCEPT
Base definition for an LED controller.