|
@@ -9,6 +9,13 @@ int intKey(const int& i) {
|
|
|
return i;
|
|
|
}
|
|
|
|
|
|
+static unsigned long seed = 0;
|
|
|
+
|
|
|
+int randomInt() {
|
|
|
+ seed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFF;
|
|
|
+ return static_cast<int>(seed >> 17);
|
|
|
+}
|
|
|
+
|
|
|
template<typename T>
|
|
|
T* countingSort(const T* in, int size, int max, int (*key)(const T&)) {
|
|
|
max++;
|
|
@@ -35,8 +42,9 @@ void cacheTest() {
|
|
|
printf("Cache Test with size = %9d | ", size);
|
|
|
constexpr int max = 500;
|
|
|
int* a = new int[size];
|
|
|
+ seed = 0;
|
|
|
for(int i = 0; i < size; i++) {
|
|
|
- a[i] = rand() % max;
|
|
|
+ a[i] = randomInt() % max;
|
|
|
}
|
|
|
long time = -getNanos();
|
|
|
int* b = countingSort(a, size, max - 1, intKey);
|
|
@@ -62,8 +70,9 @@ void structTest() {
|
|
|
printf("Struct Test with size = %9d | ", size);
|
|
|
constexpr int max = 500;
|
|
|
A* a = new A[size];
|
|
|
+ seed = 0;
|
|
|
for(int i = 0; i < size; i++) {
|
|
|
- a[i].key = rand() % max;
|
|
|
+ a[i].key = randomInt() % max;
|
|
|
}
|
|
|
long time = -getNanos();
|
|
|
A* b = countingSort(a, size, max - 1, aKey);
|
|
@@ -84,8 +93,9 @@ void pointerTest() {
|
|
|
printf("Pointer Test with size = %9d | ", size);
|
|
|
constexpr int max = 500;
|
|
|
int** a = new int*[size];
|
|
|
+ seed = 0;
|
|
|
for(int i = 0; i < size; i++) {
|
|
|
- a[i] = new int(rand() % max);
|
|
|
+ a[i] = new int(randomInt() % max);
|
|
|
}
|
|
|
long time = -getNanos();
|
|
|
int** b = countingSort<int*>(a, size, max - 1, pointerKey);
|