still buggy sp code but differently...
This commit is contained in:
parent
e83392ebaa
commit
680936f50a
@ -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
|
// Init left-right "write head" indices
|
||||||
int left = 0;
|
int left = 0;
|
||||||
int right = n - 1;
|
int right = n - 1;
|
||||||
|
|
||||||
uint32_t current = t[left];
|
uint32_t current = t[left];
|
||||||
|
bool current_is_left = true;
|
||||||
|
|
||||||
// Separate to the ends of the array (in-place)
|
// Separate to the ends of the array (in-place)
|
||||||
// We avoid the first location to hold invariant!
|
for(int i = 0; i < n; ++i) {
|
||||||
for(int i = 1; i < n; ++i) {
|
|
||||||
// TODO: maybe std::swaps below can be faster when generalizing?
|
|
||||||
if(current < mid) {
|
if(current < mid) {
|
||||||
const auto tmp = t[left];
|
const auto tmp = t[left];
|
||||||
t[left++] = current;
|
t[left++] = current;
|
||||||
current = tmp;
|
current = current_is_left ? t[left] : tmp;
|
||||||
|
current_is_left = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const auto tmp = t[right];
|
const auto tmp = t[right];
|
||||||
t[right--] = current;
|
t[right--] = current;
|
||||||
current = tmp;
|
current = tmp;
|
||||||
|
current = !current_is_left ? t[right] : tmp;
|
||||||
|
current_is_left = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
ypsu.cpp
6
ypsu.cpp
@ -32,8 +32,8 @@
|
|||||||
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", "rand",
|
"descasc", "descdesc", "smallrange",*/ "rand",
|
||||||
};
|
};
|
||||||
std::vector<uint32_t> geninput(const std::string &type, int n) {
|
std::vector<uint32_t> geninput(const std::string &type, int n) {
|
||||||
std::vector<uint32_t> v(n);
|
std::vector<uint32_t> v(n);
|
||||||
@ -395,7 +395,7 @@
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
//int n = 100000000;
|
//int n = 100000000;
|
||||||
//int n = 10000000;
|
//int n = 10000000;
|
||||||
int n = 100;
|
int n = 64;
|
||||||
for (auto inputtype : inputtypes) {
|
for (auto inputtype : inputtypes) {
|
||||||
printf("%10s", inputtype.c_str());
|
printf("%10s", inputtype.c_str());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user