wip: debugging - should be reverted?

This commit is contained in:
Richard Thier 2023-07-02 13:33:27 +02:00
parent 259ae1e540
commit 1c32648026
2 changed files with 25 additions and 8 deletions

View File

@ -586,6 +586,10 @@ static inline void ts_quicksort_inplace_impl(
// TODO: TS_UNLIKELY
if(to == 0) return;
if(from >= to - 1) return;
fprintf(stderr, "qs(%d, %d)\n", from, to);
if(from == 696203) {
puts("KULA");
}
/* For checking sorting constant array (same value always worst cases) */
TSU32 pivcnt = 0;
@ -603,6 +607,7 @@ static inline void ts_quicksort_inplace_impl(
pivi = from + (rand() % len);
}
const union tskey pivotkey = arr[pivi].key;
fprintf(stderr, "p: %d\n", pivotkey.u);
TSU32 pivoti = arr[pivi].i;
/* Main loop */
@ -614,7 +619,9 @@ static inline void ts_quicksort_inplace_impl(
TSU32 lefti = arr[left].i;
while((left < right) && lt(leftkey, pivotkey, lefti, pivoti, reent_data)) {
/* Step */
fprintf(stderr, "L... %d\n", left);
++left;
fprintf(stderr, "...L %d\n", left);
leftkey = arr[left].key;
lefti = arr[left].i;
}
@ -652,7 +659,9 @@ static inline void ts_quicksort_inplace_impl(
if(left == right) {
const union tskey leftkey = arr[left].key;
TSU32 lefti = arr[left].i;
left += (lt(leftkey, pivotkey, lefti, pivoti, reent_data));
if(lt(leftkey, pivotkey, lefti, pivoti, reent_data)) {
++left;
}
}
/* Check edge-case when left got empty. */
@ -801,6 +810,8 @@ static inline void thiersort8_internal(
TSU32 to = real_radics[i + 1];
/* Quicksort this bucket in O(mlogm), where m << n usually */
/* XXX: debuglog */
fprintf(stderr, "s(%d, %d)\n", from, to);
ts_quicksort_fromto(arr2, arr, from, 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) {
@ -532,6 +532,7 @@ int main(void) {
measure(inputtype, "std", [&] { std::sort(std::begin(w), std::end(w)); });
expected = w;
w = v;
/*
measure(inputtype, "ska", [&] { ska_sort(std::begin(w), std::end(w)); });
w = v;
measure(inputtype, "ska_copy", [&] {
@ -544,7 +545,6 @@ int main(void) {
measure(inputtype, "magyar", [&] { MagyarSort::sort<uint32_t>(&w[0], w.size()); });
assert(w == expected);
/*
w = v;
measure(inputtype, "2pass", [&] { twopass(&w[0], w.size()); });
assert(w == expected);
@ -563,10 +563,10 @@ int main(void) {
w = v;
measure(inputtype, "sp", [&] { spsort(&w[0], w.size()); });
assert(w == expected);*/
/*
w = v;
measure(inputtype, "gptbuck", [&] { gpt_bucket_sort(&w[0], w.size()); });
assert(w == expected);
/*
w = v;
measure(inputtype, "magbuck", [&] { magyar_bucket_sort(&w[0], w.size()); });
assert(w == expected);
@ -574,19 +574,25 @@ int main(void) {
measure(inputtype, "magbuck2", [&] { magyar_bucket_sort2(&w[0], w.size()); });
assert(w == expected);
*/
/*
w = v;
//w = {10, 20, 5, 200, 42, 41, 43, 5};
measure(inputtype, "qsmine", [&] { thier_quicksort(&w[0], w.size()); });
if(w != expected) {
for(uint32_t i = 0; i < n; ++i) {
// assert(w[i] == expected[i]);
if(w[i] != expected[i]) {
fprintf(stderr, "Difference at %d: %d != %d\n", i, w[i], expected[i]);
}
}
}
assert(w == expected);
*/
w = v;
measure(inputtype, "thier", [&] { thiersort_uintkey8(&w[0], w.size()); });
if(w != expected) {
for(uint32_t i = 0; i < n; ++i) {
// assert(w[i] == expected[i]);
if(w[i] != expected[i]) {
fprintf(stderr, "Difference at %d: %d != %d", i, w[i], expected[i]);
fprintf(stderr, "Difference at %d: %d != %d\n", i, w[i], expected[i]);
}
}
}