diff --git a/magyarsort.h b/magyarsort.h index 0424282..06e3a03 100644 --- a/magyarsort.h +++ b/magyarsort.h @@ -10,6 +10,7 @@ */ #include +#include #include namespace MagyarSort { @@ -31,7 +32,7 @@ namespace MagyarSort { static constexpr int SHIFT = digitChoice * BITS_PER_DIGIT; uint32_t shifted = num >> SHIFT; - return shifted & DIGIT_RANGE; + return shifted & (DIGIT_RANGE - 1); } /** Sort the given array (in-place sorting) with the given size */ @@ -48,6 +49,11 @@ namespace MagyarSort { auto d2 = getDigit<2>(arr[i]); auto d3 = getDigit<3>(arr[i]); + printf("d0:%u, arr[i]: %u\n", d0, arr[i]); + printf("d1:%u, arr[i]: %u\n", d1, arr[i]); + printf("d2:%u, arr[i]: %u\n", d2, arr[i]); + printf("d3:%u, arr[i]: %u\n", d3, arr[i]); + ++radics[d0]; ++radics[d1 + DIGIT_RANGE * 1]; ++radics[d2 + DIGIT_RANGE * 2]; @@ -58,9 +64,9 @@ namespace MagyarSort { for(size_t j = 0; j < DIGITS; ++j) { printf("d%d: ", j); for(size_t i = 0; i < DIGIT_RANGE; ++i) { - printf("%d,"); + printf("%d,", radics[i + DIGIT_RANGE*j]); } - printf("\n"); + printf("\n\n"); } } }; diff --git a/makefile b/makefile index 2eedbfb..288592c 100644 --- a/makefile +++ b/makefile @@ -1,2 +1,8 @@ -all: g++ test.cpp -o test.out -clean: rm test.out +debug: test.cpp magyarsort.h + g++ test.cpp -g -o test.out + +release: test.cpp magyarsort.h + g++ test.cpp -o test.out + +clean: test.out + rm test.out diff --git a/test.cpp b/test.cpp index 9d85bfd..c302476 100644 --- a/test.cpp +++ b/test.cpp @@ -1,10 +1,11 @@ /* LICENCE: CC3 - look it up, you need to mention me but that is all */ #include +#include #include "magyarsort.h" int main() { - uint32_t smallArr[16] = { 0xFF, 0xFFFFFFFF, 0xAA000000, 10, 20, 200, 1234513, 1, 0, 65535, 1024*1024, 1026*16, 7, 8, 1, 0} + uint32_t smallArr[16] = { 0xFF, 0xFFFFFFFF, 0xAA000000, 10, 20, 200, 1234513, 1, 0, 65535, 1024*1024, 1026*16, 7, 8, 1, 0}; MagyarSort::sort(smallArr, 16);