tested new thier and thier-qs and seems to work it looks like - constant is really slow because its the worst case for both (should be special-cased in my quicksort)

This commit is contained in:
Richard Thier 2023-07-01 04:50:32 +02:00
parent c47e8a133d
commit 4ad1c8b820
2 changed files with 10 additions and 8 deletions

View File

@ -611,7 +611,6 @@ static inline void ts_quicksort_inplace(
/* Bad case: could shrink the array by one element only */
ts_quicksort_inplace(arr, left + 1, to, lt, reent_data);
}
}
/**

View File

@ -33,8 +33,8 @@ void measure(const std::string &inputtype, const std::string &name,
worst[name] = std::max(worst[name], seconds);
}
std::vector<std::string> inputtypes = {
/* "constant", "asc", "desc", "ascasc", "ascdesc",
"descasc", "descdesc", "smallrange",*/
"constant", "asc", "desc", "ascasc", "ascdesc",
"descasc", "descdesc", "smallrange",
"rand",
};
std::vector<uint32_t> geninput(const std::string &type, int n) {
@ -410,9 +410,11 @@ void thier_quicksort(uint32_t *arr, int n) {
n, // length,
malloc);
/*
for(uint32_t i = 0; i < n; ++i) {
printf("In: %d @%d\n", tarr[i].key.u, tarr[i].i);
}
*/
// Quicksort by me
ts_quicksort_inplace(
@ -422,9 +424,11 @@ void thier_quicksort(uint32_t *arr, int n) {
ts_lt_uint,
nullptr);
/*
for(uint32_t i = 0; i < n; ++i) {
printf("Out: %d @%d\n", tarr[i].key.u, tarr[i].i);
}
*/
// Apply: O(n)
uint32_t tmp[1]; // needed for elem swaps
@ -506,9 +510,9 @@ void measure_single(int n) {
int main(void) {
//int n = 100000000;
//int n = 10000000;
//int n = 10000;
int n = 10000;
//int n = 100;
int n = 10;
//int n = 10;
printf("Sorting %d elements:\n\n", n);
@ -534,11 +538,9 @@ int main(void) {
w.swap(buf);
}
});
/*
w = v;
measure(inputtype, "magyar", [&] { MagyarSort::sort<uint32_t>(&w[0], w.size()); });
assert(w == expected);
*/
/*
w = v;
@ -570,7 +572,8 @@ int main(void) {
measure(inputtype, "magbuck2", [&] { magyar_bucket_sort2(&w[0], w.size()); });
assert(w == expected);
*/
w = {10, 20, 5, 200, 42, 41, 43, 5};
//w = {10, 20, 5, 200, 42, 41, 43, 5};
w = v;
measure(inputtype, "qsmine", [&] { thier_quicksort(&w[0], w.size()); });
assert(w == expected);
w = v;