fix dumb mistakes
This commit is contained in:
parent
33910b7e50
commit
f8d4f597c6
12
magyarsort.h
12
magyarsort.h
@ -10,6 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace MagyarSort {
|
namespace MagyarSort {
|
||||||
@ -31,7 +32,7 @@ namespace MagyarSort {
|
|||||||
static constexpr int SHIFT = digitChoice * BITS_PER_DIGIT;
|
static constexpr int SHIFT = digitChoice * BITS_PER_DIGIT;
|
||||||
|
|
||||||
uint32_t shifted = num >> SHIFT;
|
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 */
|
/** Sort the given array (in-place sorting) with the given size */
|
||||||
@ -48,6 +49,11 @@ namespace MagyarSort {
|
|||||||
auto d2 = getDigit<2>(arr[i]);
|
auto d2 = getDigit<2>(arr[i]);
|
||||||
auto d3 = getDigit<3>(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[d0];
|
||||||
++radics[d1 + DIGIT_RANGE * 1];
|
++radics[d1 + DIGIT_RANGE * 1];
|
||||||
++radics[d2 + DIGIT_RANGE * 2];
|
++radics[d2 + DIGIT_RANGE * 2];
|
||||||
@ -58,9 +64,9 @@ namespace MagyarSort {
|
|||||||
for(size_t j = 0; j < DIGITS; ++j) {
|
for(size_t j = 0; j < DIGITS; ++j) {
|
||||||
printf("d%d: ", j);
|
printf("d%d: ", j);
|
||||||
for(size_t i = 0; i < DIGIT_RANGE; ++i) {
|
for(size_t i = 0; i < DIGIT_RANGE; ++i) {
|
||||||
printf("%d,");
|
printf("%d,", radics[i + DIGIT_RANGE*j]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
10
makefile
10
makefile
@ -1,2 +1,8 @@
|
|||||||
all: g++ test.cpp -o test.out
|
debug: test.cpp magyarsort.h
|
||||||
clean: rm test.out
|
g++ test.cpp -g -o test.out
|
||||||
|
|
||||||
|
release: test.cpp magyarsort.h
|
||||||
|
g++ test.cpp -o test.out
|
||||||
|
|
||||||
|
clean: test.out
|
||||||
|
rm test.out
|
||||||
|
|||||||
3
test.cpp
3
test.cpp
@ -1,10 +1,11 @@
|
|||||||
/* LICENCE: CC3 - look it up, you need to mention me but that is all */
|
/* LICENCE: CC3 - look it up, you need to mention me but that is all */
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
#include "magyarsort.h"
|
#include "magyarsort.h"
|
||||||
|
|
||||||
int main() {
|
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);
|
MagyarSort::sort(smallArr, 16);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user