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 */
inline void spsort(uint32_t *t, int n, int m = 32);
struct lr {
int left;
int right;
};
inline struct lr internal_array_separate(uint32_t *t, int n, uint32_t low, uint32_t mid, uint32_t high) {
/** Helper function that puts elements higher then mid to the top of the array and lower to the bottom. Returns number of bottoms */
inline int internal_array_separate(uint32_t *t, int n, uint32_t mid) {
/*
// Init left-right "write head" indices
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;
eler.left = left;
eler.right = right;
return eler;
return left;
*/
// 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];
}
struct lr eler;
eler.left = left;
eler.right = right;
return eler;
return left;
}
// 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);
}
struct lr eler = internal_array_separate(t, n, low, mid, high);
auto left = eler.left;
auto right = eler.right;
auto left = internal_array_separate(t, n, mid);
auto lefts = left;
auto rights = right - left;
auto rights = n - left;
// Re-pivot the mid if needed
if(lefts < m) {