simplification + fixing right side of array not sorted because -1 counts

This commit is contained in:
Richard Thier 2022-08-16 12:25:15 +02:00
parent 6073c03f81
commit d0fa5c5b48

View File

@ -75,12 +75,8 @@ inline uint32_t internal_mid(uint32_t low, uint32_t high) {
/** Sort using space-partitioning - does recursive re-pivoting */ /** Sort using space-partitioning - does recursive re-pivoting */
inline void spsort(uint32_t *t, int n, int m = 32); inline void spsort(uint32_t *t, int n, int m = 32);
struct lr { /** Helper function that puts elements higher then mid to the top of the array and lower to the bottom. Returns number of bottoms */
int left; inline int internal_array_separate(uint32_t *t, int n, uint32_t mid) {
int right;
};
inline struct lr internal_array_separate(uint32_t *t, int n, uint32_t low, uint32_t mid, uint32_t high) {
/* /*
// Init left-right "write head" indices // Init left-right "write head" indices
int left = 0; int left = 0;
@ -105,11 +101,7 @@ inline struct lr internal_array_separate(uint32_t *t, int n, uint32_t low, uint3
} }
} }
struct lr eler; return left;
eler.left = left;
eler.right = right;
return eler;
*/ */
// FIXME: bad quality debug code to remove // FIXME: bad quality debug code to remove
@ -130,11 +122,7 @@ inline struct lr internal_array_separate(uint32_t *t, int n, uint32_t low, uint3
t[i] = v[i]; t[i] = v[i];
} }
struct lr eler; return left;
eler.left = left;
eler.right = right;
return eler;
} }
// TODO: [spsort] In-place variant that looks like a quicksort-kind-of-thing: // TODO: [spsort] In-place variant that looks like a quicksort-kind-of-thing:
@ -162,12 +150,10 @@ inline void internal_spsort(uint32_t *t, int n, int m, uint32_t low, uint32_t mi
binsertion_sort(t, n); binsertion_sort(t, n);
} }
struct lr eler = internal_array_separate(t, n, low, mid, high); auto left = internal_array_separate(t, n, mid);
auto left = eler.left;
auto right = eler.right;
auto lefts = left; auto lefts = left;
auto rights = right - left; auto rights = n - left;
// Re-pivot the mid if needed // Re-pivot the mid if needed
if(lefts < m) { if(lefts < m) {