still buggy sp code but differently...

This commit is contained in:
Richard Thier 2022-08-16 04:13:12 +02:00
parent e83392ebaa
commit 680936f50a
2 changed files with 9 additions and 8 deletions

View File

@ -101,22 +101,23 @@ inline void internal_spsort(uint32_t *t, int n, int m, uint32_t low, uint32_t mi
// Init left-right "write head" indices
int left = 0;
int right = n - 1;
uint32_t current = t[left];
bool current_is_left = true;
// Separate to the ends of the array (in-place)
// We avoid the first location to hold invariant!
for(int i = 1; i < n; ++i) {
// TODO: maybe std::swaps below can be faster when generalizing?
for(int i = 0; i < n; ++i) {
if(current < mid) {
const auto tmp = t[left];
t[left++] = current;
current = tmp;
current = current_is_left ? t[left] : tmp;
current_is_left = true;
} else {
const auto tmp = t[right];
t[right--] = current;
current = tmp;
current = !current_is_left ? t[right] : tmp;
current_is_left = false;
}
}

View File

@ -32,8 +32,8 @@
worst[name] = std::max(worst[name], seconds);
}
std::vector<std::string> inputtypes = {
"constant", "asc", "desc", "ascasc", "ascdesc",
"descasc", "descdesc", "smallrange", "rand",
/*"constant", "asc", "desc", "ascasc", "ascdesc",
"descasc", "descdesc", "smallrange",*/ "rand",
};
std::vector<uint32_t> geninput(const std::string &type, int n) {
std::vector<uint32_t> v(n);
@ -395,7 +395,7 @@
int main(void) {
//int n = 100000000;
//int n = 10000000;
int n = 100;
int n = 64;
for (auto inputtype : inputtypes) {
printf("%10s", inputtype.c_str());
fflush(stdout);