FastLED 3.10.10
Loading...
Searching...
No Matches

◆ partition3()

template<typename Iterator, typename Compare>
void fl::detail::partition3 ( Iterator first,
Iterator last,
Compare comp,
Iterator & lt_out,
Iterator & gt_out )

Definition at line 347 of file algorithm.h.

348 {
349 Iterator middle = first + (last - first) / 2;
350 Iterator pivot_iter = median_of_three(first, middle, last - 1, comp);
351 swap(*first, *pivot_iter);
352
353 Iterator lt = first; // *lt is always a pivot-equal element
354 Iterator i = first + 1;
355 Iterator gt = last;
356 while (i < gt) {
357 if (comp(*i, *lt)) {
358 swap(*lt, *i);
359 ++lt;
360 ++i;
361 } else if (comp(*lt, *i)) {
362 --gt;
363 swap(*i, *gt);
364 } else {
365 ++i;
366 }
367 }
368 lt_out = lt;
369 gt_out = gt;
370}
Iterator median_of_three(Iterator first, Iterator middle, Iterator last, Compare comp) FL_NO_EXCEPT
Definition algorithm.h:321
void swap(array< T, N > &lhs, array< T, N > &rhs) FL_NO_EXCEPT
Definition array.h:209

References fl::FL_NO_EXCEPT, median_of_three(), and fl::swap().

Referenced by quicksort_impl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: