various bugs
This commit is contained in:
parent
58176a89b6
commit
79b95bf905
18
thiersort.h
18
thiersort.h
@ -490,7 +490,7 @@ static inline TSU8 ts_radixi(
|
||||
k.f = (float)(key.i);
|
||||
|
||||
/* 8 bit float */
|
||||
k.u >> 24;
|
||||
k.u = k.u >> 24;
|
||||
|
||||
/* Need float sign trickery */
|
||||
return ts_floatsigntrick((TSU8)k.u);
|
||||
@ -502,7 +502,7 @@ static inline TSU8 ts_radixi(
|
||||
/* 8 bit float */
|
||||
/* top bit always zero so ignore it and use 8 useful bits */
|
||||
/* - this is why we shift 23 and not 24 here */
|
||||
k.u >> 23;
|
||||
k.u = k.u >> 23;
|
||||
|
||||
/* We are fine! */
|
||||
return (TSU8)k.u;
|
||||
@ -512,7 +512,7 @@ static inline TSU8 ts_radixi(
|
||||
k.f = key.f;
|
||||
|
||||
/* 8 bit float */
|
||||
k.u >> 24;
|
||||
k.u = k.u >> 24;
|
||||
|
||||
/* Need float sign trickery */
|
||||
return ts_floatsigntrick((TSU8)k.u);
|
||||
@ -534,7 +534,7 @@ static inline void ts_quicksort_inplace(
|
||||
void *reent_data),
|
||||
void *reent_data) {
|
||||
// Must do this early exit!
|
||||
if(from == to) return;
|
||||
if(from >= to) return;
|
||||
|
||||
TSU32 len = (to - from);
|
||||
TSU32 mid = from + len / 2;
|
||||
@ -576,13 +576,13 @@ static inline void ts_quicksort_inplace(
|
||||
if(left == right) {
|
||||
const union tskey leftkey = arr[left].key;
|
||||
TSU32 lefti = arr[left].i;
|
||||
left += (lt(pivotkey, leftkey, pivoti, lefti, reent_data));
|
||||
left += (lt(leftkey, pivotkey, lefti, pivoti, reent_data));
|
||||
}
|
||||
|
||||
/* Just simple recursion for now */
|
||||
ts_quicksort_inplace(arr, from, left, lt, reent_data);
|
||||
ts_quicksort_inplace(arr, left + 1, to, lt, reent_data);
|
||||
}
|
||||
ts_quicksort_inplace(arr, left, to, lt, reent_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple quicksort implementation that also moves data.
|
||||
@ -602,7 +602,7 @@ static inline void ts_quicksort_fromto(
|
||||
void *reent_data),
|
||||
void *reent_data) {
|
||||
// Must do this early exit!
|
||||
if(from == to) return;
|
||||
if(from >= to) return;
|
||||
|
||||
TSU32 len = (to - from);
|
||||
TSU32 mid = from + len / 2;
|
||||
@ -656,6 +656,8 @@ static inline void thiersort8_internal(
|
||||
/* Occurence counting O(n) */
|
||||
for(TSU32 i = 0; i < length; ++i) {
|
||||
++radics[ts_radixi(arr[i].key, isint, isunsigned, isfloat)];
|
||||
// FIXME: remove this debug code!
|
||||
// arr[i].i = ts_radixi(arr[i].key, isint, isunsigned, isfloat);
|
||||
}
|
||||
|
||||
/* Prefix sum + real radics calc O(256) */
|
||||
|
||||
25
ypsu.cpp
25
ypsu.cpp
@ -33,8 +33,9 @@ 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", "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);
|
||||
@ -409,6 +410,10 @@ 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(
|
||||
tarr,
|
||||
@ -417,6 +422,10 @@ 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
|
||||
thiersort_apply(
|
||||
@ -499,7 +508,7 @@ int main(void) {
|
||||
//int n = 10000000;
|
||||
//int n = 10000;
|
||||
//int n = 100;
|
||||
int n = 65;
|
||||
int n = 10;
|
||||
|
||||
printf("Sorting %d elements:\n\n", n);
|
||||
|
||||
@ -525,9 +534,11 @@ int main(void) {
|
||||
w.swap(buf);
|
||||
}
|
||||
});
|
||||
/*
|
||||
w = v;
|
||||
measure(inputtype, "magyar", [&] { MagyarSort::sort<uint32_t>(&w[0], w.size()); });
|
||||
assert(w == expected);
|
||||
*/
|
||||
|
||||
/*
|
||||
w = v;
|
||||
@ -547,18 +558,22 @@ int main(void) {
|
||||
assert(w == expected);
|
||||
w = v;
|
||||
measure(inputtype, "sp", [&] { spsort(&w[0], w.size()); });
|
||||
assert(w == expected);
|
||||
w = v;*/
|
||||
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);
|
||||
w = v;
|
||||
measure(inputtype, "magbuck2", [&] { magyar_bucket_sort2(&w[0], w.size()); });
|
||||
assert(w == expected);
|
||||
*/
|
||||
w = {10, 20, 5, 200, 42, 41, 43, 5};
|
||||
measure(inputtype, "qsmine", [&] { thier_quicksort(&w[0], w.size()); });
|
||||
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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user