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:
parent
c47e8a133d
commit
4ad1c8b820
@ -611,7 +611,6 @@ static inline void ts_quicksort_inplace(
|
|||||||
/* Bad case: could shrink the array by one element only */
|
/* Bad case: could shrink the array by one element only */
|
||||||
ts_quicksort_inplace(arr, left + 1, to, lt, reent_data);
|
ts_quicksort_inplace(arr, left + 1, to, lt, reent_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
17
ypsu.cpp
17
ypsu.cpp
@ -33,8 +33,8 @@ void measure(const std::string &inputtype, const std::string &name,
|
|||||||
worst[name] = std::max(worst[name], seconds);
|
worst[name] = std::max(worst[name], seconds);
|
||||||
}
|
}
|
||||||
std::vector<std::string> inputtypes = {
|
std::vector<std::string> inputtypes = {
|
||||||
/* "constant", "asc", "desc", "ascasc", "ascdesc",
|
"constant", "asc", "desc", "ascasc", "ascdesc",
|
||||||
"descasc", "descdesc", "smallrange",*/
|
"descasc", "descdesc", "smallrange",
|
||||||
"rand",
|
"rand",
|
||||||
};
|
};
|
||||||
std::vector<uint32_t> geninput(const std::string &type, int n) {
|
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,
|
n, // length,
|
||||||
malloc);
|
malloc);
|
||||||
|
|
||||||
|
/*
|
||||||
for(uint32_t i = 0; i < n; ++i) {
|
for(uint32_t i = 0; i < n; ++i) {
|
||||||
printf("In: %d @%d\n", tarr[i].key.u, tarr[i].i);
|
printf("In: %d @%d\n", tarr[i].key.u, tarr[i].i);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Quicksort by me
|
// Quicksort by me
|
||||||
ts_quicksort_inplace(
|
ts_quicksort_inplace(
|
||||||
@ -422,9 +424,11 @@ void thier_quicksort(uint32_t *arr, int n) {
|
|||||||
ts_lt_uint,
|
ts_lt_uint,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
|
/*
|
||||||
for(uint32_t i = 0; i < n; ++i) {
|
for(uint32_t i = 0; i < n; ++i) {
|
||||||
printf("Out: %d @%d\n", tarr[i].key.u, tarr[i].i);
|
printf("Out: %d @%d\n", tarr[i].key.u, tarr[i].i);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Apply: O(n)
|
// Apply: O(n)
|
||||||
uint32_t tmp[1]; // needed for elem swaps
|
uint32_t tmp[1]; // needed for elem swaps
|
||||||
@ -506,9 +510,9 @@ void measure_single(int n) {
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
//int n = 100000000;
|
//int n = 100000000;
|
||||||
//int n = 10000000;
|
//int n = 10000000;
|
||||||
//int n = 10000;
|
int n = 10000;
|
||||||
//int n = 100;
|
//int n = 100;
|
||||||
int n = 10;
|
//int n = 10;
|
||||||
|
|
||||||
printf("Sorting %d elements:\n\n", n);
|
printf("Sorting %d elements:\n\n", n);
|
||||||
|
|
||||||
@ -534,11 +538,9 @@ int main(void) {
|
|||||||
w.swap(buf);
|
w.swap(buf);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/*
|
|
||||||
w = v;
|
w = v;
|
||||||
measure(inputtype, "magyar", [&] { MagyarSort::sort<uint32_t>(&w[0], w.size()); });
|
measure(inputtype, "magyar", [&] { MagyarSort::sort<uint32_t>(&w[0], w.size()); });
|
||||||
assert(w == expected);
|
assert(w == expected);
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
w = v;
|
w = v;
|
||||||
@ -570,7 +572,8 @@ int main(void) {
|
|||||||
measure(inputtype, "magbuck2", [&] { magyar_bucket_sort2(&w[0], w.size()); });
|
measure(inputtype, "magbuck2", [&] { magyar_bucket_sort2(&w[0], w.size()); });
|
||||||
assert(w == expected);
|
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()); });
|
measure(inputtype, "qsmine", [&] { thier_quicksort(&w[0], w.size()); });
|
||||||
assert(w == expected);
|
assert(w == expected);
|
||||||
w = v;
|
w = v;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user