@@ -114,32 +114,37 @@ GPUdi() I GPUCommonAlgorithm::MedianOf3Select(I f, I l, Cmp cmp) noexcept
114114 --l;
115115
116116 if (cmp (*f, *m)) {
117- if (cmp (*m, *l))
117+ if (cmp (*m, *l)) {
118118 return m;
119- else if (cmp (*f, *l))
119+ } else if (cmp (*f, *l)) {
120120 return l;
121- else
121+ } else {
122122 return f;
123- } else if (cmp (*f, *l))
123+ }
124+ } else if (cmp (*f, *l)) {
124125 return f;
125- else if (cmp (*m, *l))
126+ } else if (cmp (*m, *l)) {
126127 return l;
127- else
128+ } else {
128129 return m;
130+ }
129131}
130132
131133template <typename I, typename T, typename Cmp>
132134GPUdi () I GPUCommonAlgorithm::UnguardedPartition(I f, I l, T piv, Cmp cmp) noexcept
133135{
134136 do {
135- while (cmp (*f, piv))
137+ while (cmp (*f, piv)) {
136138 ++f;
139+ }
137140 --l;
138- while (cmp (piv, *l))
141+ while (cmp (piv, *l)) {
139142 --l;
143+ }
140144
141- if (l <= f)
145+ if (l <= f) {
142146 return f;
147+ }
143148 IterSwap (f, l);
144149 ++f;
145150 } while (true );
@@ -148,10 +153,9 @@ GPUdi() I GPUCommonAlgorithm::UnguardedPartition(I f, I l, T piv, Cmp cmp) noexc
148153template <typename I, typename Cmp>
149154GPUdi () void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) noexcept
150155{
151- if (f == l)
152-
156+ if (f == l) {
153157 return ;
154-
158+ }
155159 using IndexType = unsigned short ;
156160
157161 struct pair {
@@ -186,15 +190,19 @@ GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) noexcept
186190 const auto lsz = pp - it0;
187191 const auto rsz = it1 - pp;
188192 if (lsz < rsz) {
189- if (rsz > cutoff)
193+ if (rsz > cutoff) {
190194 s.emplace (pp - f, it1 - f);
191- if (lsz > cutoff)
195+ }
196+ if (lsz > cutoff) {
192197 s.emplace (it0 - f, pp - f);
198+ }
193199 } else {
194- if (lsz > cutoff)
200+ if (lsz > cutoff) {
195201 s.emplace (it0 - f, pp - f);
196- if (rsz > cutoff)
202+ }
203+ if (rsz > cutoff) {
197204 s.emplace (pp - f, it1 - f);
205+ }
198206 }
199207 }
200208 InsertionSort (f, l, cmp);
0 commit comments