#include "include/private/base/SkTo.h"
#include "src/base/SkMathPriv.h"
#include <cstddef>
#include <utility>
Go to the source code of this file.
|
template<typename T , typename C > |
void | SkTHeapSort_SiftUp (T array[], size_t root, size_t bottom, const C &lessThan) |
|
template<typename T , typename C > |
void | SkTHeapSort_SiftDown (T array[], size_t root, size_t bottom, const C &lessThan) |
|
template<typename T , typename C > |
void | SkTHeapSort (T array[], size_t count, const C &lessThan) |
|
template<typename T > |
void | SkTHeapSort (T array[], size_t count) |
|
template<typename T , typename C > |
void | SkTInsertionSort (T *left, int count, const C &lessThan) |
|
template<typename T , typename C > |
T * | SkTQSort_Partition (T *left, int count, T *pivot, const C &lessThan) |
|
template<typename T , typename C > |
void | SkTIntroSort (int depth, T *left, int count, const C &lessThan) |
|
template<typename T , typename C > |
void | SkTQSort (T *begin, T *end, const C &lessThan) |
|
template<typename T > |
void | SkTQSort (T *begin, T *end) |
|
template<typename T > |
void | SkTQSort (T **begin, T **end) |
|
◆ SkTHeapSort() [1/2]
void SkTHeapSort |
( |
T |
array[], |
|
|
size_t |
count |
|
) |
| |
Sorts the array of size count using comparator '<' using a Heap Sort algorithm.
Definition at line 106 of file SkTSort.h.
106 {
108}
void SkTHeapSort(T array[], size_t count, const C &lessThan)
◆ SkTHeapSort() [2/2]
template<typename
T , typename
C >
void SkTHeapSort |
( |
T |
array[], |
|
|
size_t |
count, |
|
|
const C & |
lessThan |
|
) |
| |
Sorts the array of size count using comparator lessThan using a Heap Sort algorithm. Be sure to specialize swap if T has an efficient swap operation.
- Parameters
-
array | the array to be sorted. |
count | the number of elements in the array. |
lessThan | a functor with bool operator()(T a, T b) which returns true if a comes before b. |
Definition at line 93 of file SkTSort.h.
93 {
94 for (
size_t i =
count >> 1;
i > 0; --
i) {
96 }
97
98 for (
size_t i =
count - 1;
i > 0; --
i) {
100 swap(array[0], array[
i]);
102 }
103}
void swap(sk_sp< T > &a, sk_sp< T > &b)
void SkTHeapSort_SiftUp(T array[], size_t root, size_t bottom, const C &lessThan)
void SkTHeapSort_SiftDown(T array[], size_t root, size_t bottom, const C &lessThan)
◆ SkTHeapSort_SiftDown()
template<typename
T , typename
C >
void SkTHeapSort_SiftDown |
( |
T |
array[], |
|
|
size_t |
root, |
|
|
size_t |
bottom, |
|
|
const C & |
lessThan |
|
) |
| |
Definition at line 68 of file SkTSort.h.
68 {
70 size_t child =
root << 1;
71 while (child <= bottom) {
72 if (child < bottom && lessThan(array[child-1], array[child])) {
73 ++child;
74 }
75 if (lessThan(
x, array[child-1])) {
76 array[
root-1] = array[child-1];
79 } else {
80 break;
81 }
82 }
84}
◆ SkTHeapSort_SiftUp()
template<typename
T , typename
C >
void SkTHeapSort_SiftUp |
( |
T |
array[], |
|
|
size_t |
root, |
|
|
size_t |
bottom, |
|
|
const C & |
lessThan |
|
) |
| |
Definition at line 34 of file SkTSort.h.
34 {
38 while (j <= bottom) {
39 if (j < bottom && lessThan(array[j-1], array[j])) {
40 ++j;
41 }
42 array[
root-1] = array[j-1];
45 }
48 if (lessThan(array[j-1],
x)) {
49 array[
root-1] = array[j-1];
52 } else {
53 break;
54 }
55 }
57}
◆ SkTInsertionSort()
template<typename
T , typename
C >
void SkTInsertionSort |
( |
T * |
left, |
|
|
int |
count, |
|
|
const C & |
lessThan |
|
) |
| |
Sorts the array of size count using comparator lessThan using an Insertion Sort algorithm.
Definition at line 114 of file SkTSort.h.
114 {
117 if (!lessThan(*
next, *(
next - 1))) {
118 continue;
119 }
120 T insert = std::move(*
next);
122 do {
123 *hole = std::move(*(hole - 1));
124 --hole;
125 }
while (
left < hole && lessThan(insert, *(hole - 1)));
126 *hole = std::move(insert);
127 }
128}
static float next(float f)
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
◆ SkTIntroSort()
template<typename
T , typename
C >
void SkTIntroSort |
( |
int |
depth, |
|
|
T * |
left, |
|
|
int |
count, |
|
|
const C & |
lessThan |
|
) |
| |
Definition at line 163 of file SkTSort.h.
163 {
164 for (;;) {
167 return;
168 }
169
170 if (depth == 0) {
172 return;
173 }
174 --depth;
175
178 int pivotCount = pivot -
left;
179
181 left += pivotCount + 1;
182 count -= pivotCount + 1;
183 }
184}
void SkTIntroSort(int depth, T *left, int count, const C &lessThan)
T * SkTQSort_Partition(T *left, int count, T *pivot, const C &lessThan)
void SkTInsertionSort(T *left, int count, const C &lessThan)
◆ SkTQSort() [1/3]
void SkTQSort |
( |
T ** |
begin, |
|
|
T ** |
end |
|
) |
| |
Sorts the region from left to right using comparator '*a < *b' using Introsort.
Definition at line 210 of file SkTSort.h.
210 {
212}
void SkTQSort(T *begin, T *end, const C &lessThan)
static const char * begin(const StringSlice &s)
◆ SkTQSort() [2/3]
void SkTQSort |
( |
T * |
begin, |
|
|
T * |
end |
|
) |
| |
Sorts the region from left to right using comparator 'a < b' using Introsort.
Definition at line 205 of file SkTSort.h.
◆ SkTQSort() [3/3]
template<typename
T , typename
C >
void SkTQSort |
( |
T * |
begin, |
|
|
T * |
end, |
|
|
const C & |
lessThan |
|
) |
| |
Sorts the region from left to right using comparator lessThan using Introsort. Be sure to specialize swap
if T has an efficient swap operation.
- Parameters
-
begin | points to the beginning of the region to be sorted |
end | points past the end of the region to be sorted |
lessThan | a functor/lambda which returns true if a comes before b. |
Definition at line 194 of file SkTSort.h.
194 {
196 if (n <= 1) {
197 return;
198 }
199
202}
static int SkNextLog2(uint32_t value)
constexpr int SkToInt(S x)
◆ SkTQSort_Partition()
template<typename
T , typename
C >
T * SkTQSort_Partition |
( |
T * |
left, |
|
|
int |
count, |
|
|
T * |
pivot, |
|
|
const C & |
lessThan |
|
) |
| |
Definition at line 133 of file SkTSort.h.
133 {
136 T pivotValue = *pivot;
140 if (lessThan(*
left, pivotValue)) {
142 newPivot += 1;
143 }
145 }
147 return newPivot;
148}