From 680936f50a2008cacaa899f527da4de000901d8b Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Tue, 16 Aug 2022 04:13:12 +0200 Subject: [PATCH] still buggy sp code but differently... --- space_partitioning_sort/spsort.h | 11 ++++++----- ypsu.cpp | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/space_partitioning_sort/spsort.h b/space_partitioning_sort/spsort.h index 91d428e..ae29733 100644 --- a/space_partitioning_sort/spsort.h +++ b/space_partitioning_sort/spsort.h @@ -101,22 +101,23 @@ inline void internal_spsort(uint32_t *t, int n, int m, uint32_t low, uint32_t mi // Init left-right "write head" indices int left = 0; int right = n - 1; - uint32_t current = t[left]; + bool current_is_left = true; // Separate to the ends of the array (in-place) - // We avoid the first location to hold invariant! - for(int i = 1; i < n; ++i) { - // TODO: maybe std::swaps below can be faster when generalizing? + for(int i = 0; i < n; ++i) { if(current < mid) { const auto tmp = t[left]; t[left++] = current; - current = tmp; + current = current_is_left ? t[left] : tmp; + current_is_left = true; } else { const auto tmp = t[right]; t[right--] = current; current = tmp; + current = !current_is_left ? t[right] : tmp; + current_is_left = false; } } diff --git a/ypsu.cpp b/ypsu.cpp index 1b39d96..c0fb400 100644 --- a/ypsu.cpp +++ b/ypsu.cpp @@ -32,8 +32,8 @@ worst[name] = std::max(worst[name], seconds); } std::vector inputtypes = { - "constant", "asc", "desc", "ascasc", "ascdesc", - "descasc", "descdesc", "smallrange", "rand", + /*"constant", "asc", "desc", "ascasc", "ascdesc", + "descasc", "descdesc", "smallrange",*/ "rand", }; std::vector geninput(const std::string &type, int n) { std::vector v(n); @@ -395,7 +395,7 @@ int main(void) { //int n = 100000000; //int n = 10000000; - int n = 100; + int n = 64; for (auto inputtype : inputtypes) { printf("%10s", inputtype.c_str()); fflush(stdout);