more of latest changes - random weird shiiit
This commit is contained in:
parent
f24b3987c0
commit
da4d122ee1
17
magyarsort.h
17
magyarsort.h
@ -242,10 +242,10 @@ namespace MagyarSort {
|
||||
/** Recursive Functor: no class should be generated I think (compiler should be smart) */
|
||||
template<int DIGIT, typename COUNTER_TYP>
|
||||
struct RadixMagic : public RadixMagic<DIGIT - 1, COUNTER_TYP> {
|
||||
inline __attribute__((always_inline)) RadixMagic(COUNTER_TYP *radics, uint32_t *from, uint32_t *to, COUNTER_TYP size) noexcept
|
||||
: RadixMagic<DIGIT - 1, COUNTER_TYP>(radics, from, to, size) {
|
||||
inline __attribute__((always_inline)) RadixMagic(bool &swapped, COUNTER_TYP *radics, uint32_t *from, uint32_t *to, COUNTER_TYP size) noexcept
|
||||
: RadixMagic<DIGIT - 1, COUNTER_TYP>(swapped, radics, from, to, size) {
|
||||
// Tricky: see (**)
|
||||
if(this->swapped) { // never true for DIGIT 0
|
||||
if(swapped) { // never true for DIGIT 0, see (***)
|
||||
std::swap(from, to);
|
||||
}
|
||||
|
||||
@ -274,14 +274,13 @@ namespace MagyarSort {
|
||||
//debugArr(to, size);
|
||||
|
||||
// (**) Only swaps pointers above in the child class constructor IF NEEDED :-)
|
||||
this->swapped = !this->swapped;
|
||||
swapped = !swapped;
|
||||
}
|
||||
};
|
||||
/** Ends template recursion */
|
||||
template<typename COUNTER_TYP>
|
||||
struct RadixMagic<-1, COUNTER_TYP> {
|
||||
bool swapped = false;
|
||||
inline RadixMagic(COUNTER_TYP *radics, uint32_t *&from, uint32_t *&to, COUNTER_TYP size) noexcept { }
|
||||
inline RadixMagic(bool swapped, COUNTER_TYP *radics, uint32_t *&from, uint32_t *&to, COUNTER_TYP size) noexcept {}
|
||||
};
|
||||
|
||||
/* SORT */
|
||||
@ -361,13 +360,15 @@ namespace MagyarSort {
|
||||
|
||||
uint32_t *from = arr;
|
||||
uint32_t *to = &arc[0];
|
||||
static thread_local bool swapped;
|
||||
swapped = false; // must be separate line
|
||||
|
||||
RadixMagic<DIGITS - 1, COUNTER_TYP> r(radics, from, to, size);
|
||||
RadixMagic<DIGITS - 1, COUNTER_TYP> r(swapped, radics, from, to, size);
|
||||
|
||||
// With an other API we could spare this copy if we can delete original arr and return ptr or something...
|
||||
// I am fine with this... this is not my main idea anyways, just little ILP tweak to regular radix sort
|
||||
//if(to != arr) // <- logically, but bad they are already swapped here!!! BEWARE
|
||||
if(r.swapped) { // <- in reality this is what we want because of last swap happened anyways!
|
||||
if(swapped) { // <- in reality this is what we want because of last swap happened anyways!
|
||||
memcpy(arr, to, size);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user