From 95c759b9e3b47829f23598ac1f03303ff085e813 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Fri, 9 May 2025 05:05:40 +0200 Subject: [PATCH] swab: fixed == to >= typo - now beats std::sort and is comparison sort fully! --- schwab_sort.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/schwab_sort.h b/schwab_sort.h index e36740c..e4dcbe9 100644 --- a/schwab_sort.h +++ b/schwab_sort.h @@ -16,7 +16,7 @@ /** Below this many elements we do insertion sort */ #ifndef SCHWAB_INSERTION_THRESHOLD -#define SCHWAB_INSERTION_THRESHOLD 4 +#define SCHWAB_INSERTION_THRESHOLD 64 #endif /* SCHWAB_DELTA_THRESHOLD */ typedef uint32_t sch_rand_state; @@ -187,7 +187,7 @@ static inline int schwab_partition( arr[b3] = arr[b2]; arr[b2] = (where == 2) ? arr[b2] : arr[b1]; - arr[b1] = (where == 1) ? arr[b1] : arr[b0]; + arr[b1] = (where >= 1) ? arr[b1] : arr[b0]; ++b2; b1 += (where < 2); @@ -244,7 +244,7 @@ static inline void schwab_sort( /* Loop handles longest sub-sort-task which ensused log tree depth */ /* Loop also handles start condition */ while(low < high) { - if(1 /*high - low > SCHWAB_INSERTION_THRESHOLD*/) { + if(high - low > SCHWAB_INSERTION_THRESHOLD) { int r0 = schwab_pick_pivot(state, (high + 1) - low) + low; int r1 = schwab_pick_pivot(state, (high + 1) - low) + low; uint32_t klo = array[r0];