minor tweaks
This commit is contained in:
parent
76ba29018d
commit
62dcda6bf2
@ -62,7 +62,7 @@ namespace MagyarSort {
|
|||||||
/* HELPERS */
|
/* HELPERS */
|
||||||
|
|
||||||
template<int DIGIT_CHOICE>
|
template<int DIGIT_CHOICE>
|
||||||
static inline uint32_t getDigit(uint32_t num) noexcept {
|
static inline __attribute__((always_inline)) uint32_t getDigit(uint32_t num) noexcept {
|
||||||
static constexpr int SHIFT = DIGIT_CHOICE * BITS_PER_DIGIT;
|
static constexpr int SHIFT = DIGIT_CHOICE * BITS_PER_DIGIT;
|
||||||
|
|
||||||
uint32_t shifted = num >> SHIFT;
|
uint32_t shifted = num >> SHIFT;
|
||||||
@ -72,7 +72,7 @@ namespace MagyarSort {
|
|||||||
/** Recursive Functor: no class should be generated I think (compiler should be smart) */
|
/** Recursive Functor: no class should be generated I think (compiler should be smart) */
|
||||||
template<int DIGIT>
|
template<int DIGIT>
|
||||||
struct OccurenceMagic : public OccurenceMagic<DIGIT - 1> {
|
struct OccurenceMagic : public OccurenceMagic<DIGIT - 1> {
|
||||||
inline OccurenceMagic(uint32_t arr[], size_t i, size_t *radicsOut) noexcept
|
inline __attribute__((always_inline)) OccurenceMagic(uint32_t arr[], size_t i, size_t *radicsOut) noexcept
|
||||||
: OccurenceMagic<DIGIT -1 >(arr, i, radicsOut) {
|
: OccurenceMagic<DIGIT -1 >(arr, i, radicsOut) {
|
||||||
// Parents run first so template recursion runs DIGIT=0 first...
|
// Parents run first so template recursion runs DIGIT=0 first...
|
||||||
++radicsOut[getDigit<DIGIT>(arr[i]) + DIGIT_RANGE * DIGIT];
|
++radicsOut[getDigit<DIGIT>(arr[i]) + DIGIT_RANGE * DIGIT];
|
||||||
@ -94,7 +94,7 @@ namespace MagyarSort {
|
|||||||
/** Recursive Functor: no class should be generated I think (compiler should be smart) */
|
/** Recursive Functor: no class should be generated I think (compiler should be smart) */
|
||||||
template<int DIGIT>
|
template<int DIGIT>
|
||||||
struct PrefixMagic : public PrefixMagic<DIGIT - 1> {
|
struct PrefixMagic : public PrefixMagic<DIGIT - 1> {
|
||||||
inline PrefixMagic(size_t *radics, size_t *prev, int i) noexcept
|
inline __attribute__((always_inline)) PrefixMagic(size_t *radics, size_t *prev, int i) noexcept
|
||||||
: PrefixMagic<DIGIT - 1>(radics, prev, i) {
|
: PrefixMagic<DIGIT - 1>(radics, prev, i) {
|
||||||
static constexpr int DSTART = (DIGIT * DIGIT_RANGE);
|
static constexpr int DSTART = (DIGIT * DIGIT_RANGE);
|
||||||
radics[DSTART + i] += prev[DIGIT];
|
radics[DSTART + i] += prev[DIGIT];
|
||||||
@ -109,7 +109,7 @@ namespace MagyarSort {
|
|||||||
|
|
||||||
/** Gets REFERENCE to the given digit from the radix-array that has more than one digits */
|
/** Gets REFERENCE to the given digit from the radix-array that has more than one digits */
|
||||||
template<int DIGIT>
|
template<int DIGIT>
|
||||||
static inline size_t &rGet(size_t *radics, size_t i) noexcept {
|
static inline __attribute__((always_inline)) size_t &rGet(size_t *radics, size_t i) noexcept {
|
||||||
static constexpr int DSTART = (DIGIT * DIGIT_RANGE);
|
static constexpr int DSTART = (DIGIT * DIGIT_RANGE);
|
||||||
return radics[DSTART + i];
|
return radics[DSTART + i];
|
||||||
}
|
}
|
||||||
|
|||||||
36
test.cpp
36
test.cpp
@ -14,7 +14,7 @@
|
|||||||
// Uncomment if you want to see output before / after sorts (debugging for example)
|
// Uncomment if you want to see output before / after sorts (debugging for example)
|
||||||
//#define PRINT_OUTPUT
|
//#define PRINT_OUTPUT
|
||||||
|
|
||||||
//#define SKA_SORT
|
#define SKA_SORT
|
||||||
|
|
||||||
/* Includes */
|
/* Includes */
|
||||||
|
|
||||||
@ -87,23 +87,6 @@ int main() {
|
|||||||
std::vector<uint32_t> in1 = GenerateInput();;
|
std::vector<uint32_t> in1 = GenerateInput();;
|
||||||
std::vector<uint32_t> in2 = in1; // copy
|
std::vector<uint32_t> in2 = in1; // copy
|
||||||
|
|
||||||
uint32_t *arr1 = &(in1[0]);
|
|
||||||
|
|
||||||
#ifdef PRINT_OUTPUT
|
|
||||||
printf("Inp: ");
|
|
||||||
MagyarSort::debugArr(arr1, in1.size());
|
|
||||||
#endif // PRINT_OUTPUT
|
|
||||||
|
|
||||||
/* Our sort */
|
|
||||||
auto ourBegin = std::chrono::high_resolution_clock::now();
|
|
||||||
MagyarSort::sort(arr1, in1.size());
|
|
||||||
auto ourEnd = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
#ifdef PRINT_OUTPUT
|
|
||||||
printf("Our: ");
|
|
||||||
MagyarSort::debugArr(arr1, in1.size());
|
|
||||||
#endif // PRINT_OUTPUT
|
|
||||||
|
|
||||||
auto stdBegin = std::chrono::high_resolution_clock::now();
|
auto stdBegin = std::chrono::high_resolution_clock::now();
|
||||||
#ifndef SKA_SORT
|
#ifndef SKA_SORT
|
||||||
/* std::sort */
|
/* std::sort */
|
||||||
@ -121,6 +104,23 @@ int main() {
|
|||||||
MagyarSort::debugArr(&in2[0], in2.size());
|
MagyarSort::debugArr(&in2[0], in2.size());
|
||||||
#endif // PRINT_OUTPUT
|
#endif // PRINT_OUTPUT
|
||||||
|
|
||||||
|
uint32_t *arr1 = &(in1[0]);
|
||||||
|
|
||||||
|
#ifdef PRINT_OUTPUT
|
||||||
|
printf("Inp: ");
|
||||||
|
MagyarSort::debugArr(arr1, in1.size());
|
||||||
|
#endif // PRINT_OUTPUT
|
||||||
|
|
||||||
|
/* Our sort */
|
||||||
|
auto ourBegin = std::chrono::high_resolution_clock::now();
|
||||||
|
MagyarSort::sort(arr1, in1.size());
|
||||||
|
auto ourEnd = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
#ifdef PRINT_OUTPUT
|
||||||
|
printf("Our: ");
|
||||||
|
MagyarSort::debugArr(arr1, in1.size());
|
||||||
|
#endif // PRINT_OUTPUT
|
||||||
|
|
||||||
/* Check against std - the real test */
|
/* Check against std - the real test */
|
||||||
|
|
||||||
bool good = true;
|
bool good = true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user