You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5686fda
Browse filesBrowse the repository at this point in the historyBrowse files
template <typename IndexType, typename I, typename Cmp>
59
+
GPUd() staticvoidQuickSortImpl(I f, I l, Cmp cmp) GPUnoexcept(); // Quicksort implementation with index type IndexType, which must be able to hold the number of elements
59
60
60
-
// Insertionsort implementation
61
61
template <typename I, typename Cmp>
62
-
GPUd() staticvoidInsertionSort(I f, I l, Cmp cmp) GPUnoexcept();
62
+
GPUd() staticvoidInsertionSort(I f, I l, Cmp cmp) GPUnoexcept();// Insertionsort implementation
63
63
64
-
// Helper for Quicksort implementation
65
64
template <typename I, typename Cmp>
66
-
GPUd() static I MedianOf3Select(I f, I l, Cmp cmp) GPUnoexcept();
65
+
GPUd() static I MedianOf3Select(I f, I l, Cmp cmp) GPUnoexcept();// Helper for Quicksort implementation
67
66
68
-
// Helper for Quicksort implementation
69
67
template <typename I, typename T, typename Cmp>
70
-
GPUd() static I UnguardedPartition(I f, I l, T piv, Cmp cmp) GPUnoexcept();
68
+
GPUd() static I UnguardedPartition(I f, I l, T piv, Cmp cmp) GPUnoexcept();// Helper for Quicksort implementation
71
69
72
-
// Helper
73
70
template <typename I>
74
-
GPUd() staticvoidIterSwap(I a, I b) GPUnoexcept();
71
+
GPUd() staticvoidIterSwap(I a, I b) GPUnoexcept();// Helper
75
72
};
76
73
77
74
#ifndef GPUCA_ALGORITHM_STD
@@ -147,19 +144,28 @@ GPUdi() I GPUCommonAlgorithm::UnguardedPartition(I f, I l, T piv, Cmp cmp) GPUno
147
144
148
145
template <typename I, typename Cmp>
149
146
GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) GPUnoexcept()
147
+
{
148
+
if (l - f <= 0xFFFF) {
149
+
QuickSortImpl<uint16_t>(f, l, cmp);
150
+
} else {
151
+
QuickSortImpl<uint32_t>(f, l, cmp);
152
+
}
153
+
}
154
+
155
+
template <typename IndexType, typename I, typename Cmp>
156
+
GPUdi() void GPUCommonAlgorithm::QuickSortImpl(I f, I l, Cmp cmp) GPUnoexcept()
150
157
{
151
158
if (f == l) {
152
159
return;
153
160
}
154
-
using IndexType = uint16_t;
155
161
156
162
structpair {
157
163
IndexType first;
158
164
IndexType second;
159
165
};
160
166
161
167
structStack {
162
-
pair data[11];
168
+
pair data[sizeof(IndexType) * 8 - 4]; // The smaller partition is processed first, so the depth is bounded by log2(n / cutoff) + 1, cutoff = 50 > 2^5
0 commit comments