swab: fixed == to >= typo - now beats std::sort and is comparison sort fully!

This commit is contained in:
Richard Thier 2025-05-09 05:05:40 +02:00
parent 147ca60672
commit 95c759b9e3

View File

@ -16,7 +16,7 @@
/** Below this many elements we do insertion sort */ /** Below this many elements we do insertion sort */
#ifndef SCHWAB_INSERTION_THRESHOLD #ifndef SCHWAB_INSERTION_THRESHOLD
#define SCHWAB_INSERTION_THRESHOLD 4 #define SCHWAB_INSERTION_THRESHOLD 64
#endif /* SCHWAB_DELTA_THRESHOLD */ #endif /* SCHWAB_DELTA_THRESHOLD */
typedef uint32_t sch_rand_state; typedef uint32_t sch_rand_state;
@ -187,7 +187,7 @@ static inline int schwab_partition(
arr[b3] = arr[b2]; arr[b3] = arr[b2];
arr[b2] = (where == 2) ? arr[b2] : arr[b1]; 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; ++b2;
b1 += (where < 2); b1 += (where < 2);
@ -244,7 +244,7 @@ static inline void schwab_sort(
/* Loop handles longest sub-sort-task which ensused log tree depth */ /* Loop handles longest sub-sort-task which ensused log tree depth */
/* Loop also handles start condition */ /* Loop also handles start condition */
while(low < high) { 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 r0 = schwab_pick_pivot(state, (high + 1) - low) + low;
int r1 = schwab_pick_pivot(state, (high + 1) - low) + low; int r1 = schwab_pick_pivot(state, (high + 1) - low) + low;
uint32_t klo = array[r0]; uint32_t klo = array[r0];