From 4ad1c8b820e2e97c881128706d9787392fe786fb Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Sat, 1 Jul 2023 04:50:32 +0200 Subject: [PATCH] tested new thier and thier-qs and seems to work it looks like - constant is really slow because its the worst case for both (should be special-cased in my quicksort) --- thiersort.h | 1 - ypsu.cpp | 17 ++++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/thiersort.h b/thiersort.h index 1e9b827..56341a1 100644 --- a/thiersort.h +++ b/thiersort.h @@ -611,7 +611,6 @@ static inline void ts_quicksort_inplace( /* Bad case: could shrink the array by one element only */ ts_quicksort_inplace(arr, left + 1, to, lt, reent_data); } - } /** diff --git a/ypsu.cpp b/ypsu.cpp index 185ce63..abdc0bb 100644 --- a/ypsu.cpp +++ b/ypsu.cpp @@ -33,8 +33,8 @@ void measure(const std::string &inputtype, const std::string &name, worst[name] = std::max(worst[name], seconds); } std::vector inputtypes = { - /* "constant", "asc", "desc", "ascasc", "ascdesc", - "descasc", "descdesc", "smallrange",*/ + "constant", "asc", "desc", "ascasc", "ascdesc", + "descasc", "descdesc", "smallrange", "rand", }; std::vector geninput(const std::string &type, int n) { @@ -410,9 +410,11 @@ void thier_quicksort(uint32_t *arr, int n) { n, // length, malloc); + /* for(uint32_t i = 0; i < n; ++i) { printf("In: %d @%d\n", tarr[i].key.u, tarr[i].i); } + */ // Quicksort by me ts_quicksort_inplace( @@ -422,9 +424,11 @@ void thier_quicksort(uint32_t *arr, int n) { ts_lt_uint, nullptr); + /* for(uint32_t i = 0; i < n; ++i) { printf("Out: %d @%d\n", tarr[i].key.u, tarr[i].i); } + */ // Apply: O(n) uint32_t tmp[1]; // needed for elem swaps @@ -506,9 +510,9 @@ void measure_single(int n) { int main(void) { //int n = 100000000; //int n = 10000000; - //int n = 10000; + int n = 10000; //int n = 100; - int n = 10; + //int n = 10; printf("Sorting %d elements:\n\n", n); @@ -534,11 +538,9 @@ int main(void) { w.swap(buf); } }); - /* w = v; measure(inputtype, "magyar", [&] { MagyarSort::sort(&w[0], w.size()); }); assert(w == expected); - */ /* w = v; @@ -570,7 +572,8 @@ int main(void) { measure(inputtype, "magbuck2", [&] { magyar_bucket_sort2(&w[0], w.size()); }); assert(w == expected); */ - w = {10, 20, 5, 200, 42, 41, 43, 5}; + //w = {10, 20, 5, 200, 42, 41, 43, 5}; + w = v; measure(inputtype, "qsmine", [&] { thier_quicksort(&w[0], w.size()); }); assert(w == expected); w = v;