[libcxx-commits] [libcxx] [libcxx][algorithm] Optimize std::stable_sort via radix sort algorithm (PR #104683)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 10 12:48:20 PST 2024
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40L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github.com>
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff f3cf24fcc46ab1b9612d7dcb55ec5f18ea2dc62f a0c3857e0701b5ec89e45eaf29bbd546deed6aa8 --extensions cpp,h -- libcxx/include/__algorithm/radix_sort.h libcxx/include/__algorithm/stable_sort.h libcxx/include/__bit/bit_log2.h libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
index 3fcaeec90c..730f7080cf 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
@@ -50,15 +50,13 @@ template <class RI>
void
test_sort_driver_driver(RI f, RI l, int start, RI real_last)
{
- typedef typename std::iterator_traits<RI>::value_type value_type;
+ typedef typename std::iterator_traits<RI>::value_type value_type;
- for (RI i = l; i > f + start;)
- {
- *--i = static_cast<value_type>(start);
- if (f == i)
- {
- test_sort_helper(f, real_last);
- }
+ for (RI i = l; i > f + start;) {
+ *--i = static_cast<value_type>(start);
+ if (f == i) {
+ test_sort_helper(f, real_last);
+ }
if (start > 0)
test_sort_driver_driver(f, i, start-1, real_last);
}
@@ -72,70 +70,60 @@ test_sort_driver(RI f, RI l, int start)
}
template <int sa, class V>
-void
-test_sort_()
-{
- V ia[sa];
- for (int i = 0; i < sa; ++i)
- {
- test_sort_driver(ia, ia+sa, i);
- }
+void test_sort_() {
+ V ia[sa];
+ for (int i = 0; i < sa; ++i) {
+ test_sort_driver(ia, ia + sa, i);
+ }
}
template <int sa>
-void
-test_sort_()
-{
- test_sort_<sa, int>();
- test_sort_<sa, float>();
+void test_sort_() {
+ test_sort_<sa, int>();
+ test_sort_<sa, float>();
}
template <class V>
-void
-test_larger_sorts(int N, int M)
-{
- assert(N != 0);
- assert(M != 0);
- // create array length N filled with M different numbers
- V* array = new V[N];
- int x = 0;
- for (int i = 0; i < N; ++i)
- {
- array[i] = static_cast<V>(x);
- if (++x == M)
- x = 0;
- }
- // test saw tooth pattern
- std::stable_sort(array, array+N);
- assert(std::is_sorted(array, array+N));
- // test random pattern
- std::shuffle(array, array+N, randomness);
- std::stable_sort(array, array+N);
- assert(std::is_sorted(array, array+N));
- // test sorted pattern
- std::stable_sort(array, array+N);
- assert(std::is_sorted(array, array+N));
- // test reverse sorted pattern
- std::reverse(array, array+N);
- std::stable_sort(array, array+N);
- assert(std::is_sorted(array, array+N));
- // test swap ranges 2 pattern
- std::swap_ranges(array, array+N/2, array+N/2);
- std::stable_sort(array, array+N);
- assert(std::is_sorted(array, array+N));
- // test reverse swap ranges 2 pattern
- std::reverse(array, array+N);
- std::swap_ranges(array, array+N/2, array+N/2);
- std::stable_sort(array, array+N);
- assert(std::is_sorted(array, array+N));
- delete [] array;
+void test_larger_sorts(int N, int M) {
+ assert(N != 0);
+ assert(M != 0);
+ // create array length N filled with M different numbers
+ V* array = new V[N];
+ int x = 0;
+ for (int i = 0; i < N; ++i) {
+ array[i] = static_cast<V>(x);
+ if (++x == M)
+ x = 0;
+ }
+ // test saw tooth pattern
+ std::stable_sort(array, array + N);
+ assert(std::is_sorted(array, array + N));
+ // test random pattern
+ std::shuffle(array, array + N, randomness);
+ std::stable_sort(array, array + N);
+ assert(std::is_sorted(array, array + N));
+ // test sorted pattern
+ std::stable_sort(array, array + N);
+ assert(std::is_sorted(array, array + N));
+ // test reverse sorted pattern
+ std::reverse(array, array + N);
+ std::stable_sort(array, array + N);
+ assert(std::is_sorted(array, array + N));
+ // test swap ranges 2 pattern
+ std::swap_ranges(array, array + N / 2, array + N / 2);
+ std::stable_sort(array, array + N);
+ assert(std::is_sorted(array, array + N));
+ // test reverse swap ranges 2 pattern
+ std::reverse(array, array + N);
+ std::swap_ranges(array, array + N / 2, array + N / 2);
+ std::stable_sort(array, array + N);
+ assert(std::is_sorted(array, array + N));
+ delete[] array;
}
-void
-test_larger_sorts(int N, int M)
-{
- test_larger_sorts<int>(N, M);
- test_larger_sorts<float>(N, M);
+void test_larger_sorts(int N, int M) {
+ test_larger_sorts<int>(N, M);
+ test_larger_sorts<float>(N, M);
}
void
``````````
</details>
https://github.com/llvm/llvm-project/pull/104683
More information about the libcxx-commits
mailing list