From 1c3264802646d8efdf88258722a98065d130c432 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Sun, 2 Jul 2023 13:33:27 +0200 Subject: [PATCH] wip: debugging - should be reverted? --- thiersort.h | 13 ++++++++++++- ypsu.cpp | 20 +++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/thiersort.h b/thiersort.h index 4ff7758..5c6ef11 100644 --- a/thiersort.h +++ b/thiersort.h @@ -586,6 +586,10 @@ static inline void ts_quicksort_inplace_impl( // TODO: TS_UNLIKELY if(to == 0) return; if(from >= to - 1) return; +fprintf(stderr, "qs(%d, %d)\n", from, to); +if(from == 696203) { + puts("KULA"); +} /* For checking sorting constant array (same value always worst cases) */ TSU32 pivcnt = 0; @@ -603,6 +607,7 @@ static inline void ts_quicksort_inplace_impl( pivi = from + (rand() % len); } const union tskey pivotkey = arr[pivi].key; +fprintf(stderr, "p: %d\n", pivotkey.u); TSU32 pivoti = arr[pivi].i; /* Main loop */ @@ -614,7 +619,9 @@ static inline void ts_quicksort_inplace_impl( TSU32 lefti = arr[left].i; while((left < right) && lt(leftkey, pivotkey, lefti, pivoti, reent_data)) { /* Step */ +fprintf(stderr, "L... %d\n", left); ++left; +fprintf(stderr, "...L %d\n", left); leftkey = arr[left].key; lefti = arr[left].i; } @@ -652,7 +659,9 @@ static inline void ts_quicksort_inplace_impl( if(left == right) { const union tskey leftkey = arr[left].key; TSU32 lefti = arr[left].i; - left += (lt(leftkey, pivotkey, lefti, pivoti, reent_data)); + if(lt(leftkey, pivotkey, lefti, pivoti, reent_data)) { + ++left; + } } /* Check edge-case when left got empty. */ @@ -801,6 +810,8 @@ static inline void thiersort8_internal( TSU32 to = real_radics[i + 1]; /* Quicksort this bucket in O(mlogm), where m << n usually */ + /* XXX: debuglog */ + fprintf(stderr, "s(%d, %d)\n", from, to); ts_quicksort_fromto(arr2, arr, from, to, lt, reent_data); } diff --git a/ypsu.cpp b/ypsu.cpp index f7a0c9c..9472d28 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) { @@ -532,6 +532,7 @@ int main(void) { measure(inputtype, "std", [&] { std::sort(std::begin(w), std::end(w)); }); expected = w; w = v; + /* measure(inputtype, "ska", [&] { ska_sort(std::begin(w), std::end(w)); }); w = v; measure(inputtype, "ska_copy", [&] { @@ -544,7 +545,6 @@ int main(void) { measure(inputtype, "magyar", [&] { MagyarSort::sort(&w[0], w.size()); }); assert(w == expected); - /* w = v; measure(inputtype, "2pass", [&] { twopass(&w[0], w.size()); }); assert(w == expected); @@ -563,10 +563,10 @@ int main(void) { w = v; measure(inputtype, "sp", [&] { spsort(&w[0], w.size()); }); assert(w == expected);*/ + /* w = v; measure(inputtype, "gptbuck", [&] { gpt_bucket_sort(&w[0], w.size()); }); assert(w == expected); - /* w = v; measure(inputtype, "magbuck", [&] { magyar_bucket_sort(&w[0], w.size()); }); assert(w == expected); @@ -574,19 +574,25 @@ int main(void) { measure(inputtype, "magbuck2", [&] { magyar_bucket_sort2(&w[0], w.size()); }); assert(w == expected); */ - /* w = v; //w = {10, 20, 5, 200, 42, 41, 43, 5}; measure(inputtype, "qsmine", [&] { thier_quicksort(&w[0], w.size()); }); + if(w != expected) { + for(uint32_t i = 0; i < n; ++i) { + // assert(w[i] == expected[i]); + if(w[i] != expected[i]) { + fprintf(stderr, "Difference at %d: %d != %d\n", i, w[i], expected[i]); + } + } + } assert(w == expected); - */ w = v; measure(inputtype, "thier", [&] { thiersort_uintkey8(&w[0], w.size()); }); if(w != expected) { for(uint32_t i = 0; i < n; ++i) { // assert(w[i] == expected[i]); if(w[i] != expected[i]) { - fprintf(stderr, "Difference at %d: %d != %d", i, w[i], expected[i]); + fprintf(stderr, "Difference at %d: %d != %d\n", i, w[i], expected[i]); } } }