|
@@ -1,10 +1,10 @@
|
|
|
|
|
|
// #define PROFILE_MTMERGESORT
|
|
// #define PROFILE_MTMERGESORT
|
|
|
|
|
|
-template<typename T> static int compare(const void *a, const void *b);
|
|
|
|
|
|
+template<typename T> static int compare_keys(const void *a, const void *b);
|
|
|
|
|
|
template<>
|
|
template<>
|
|
-int compare<uint64_t>(const void *a, const void *b)
|
|
|
|
|
|
+int compare_keys<uint64_t>(const void *a, const void *b)
|
|
{
|
|
{
|
|
uint32_t *a32 = (uint32_t*)a;
|
|
uint32_t *a32 = (uint32_t*)a;
|
|
uint32_t *b32 = (uint32_t*)b;
|
|
uint32_t *b32 = (uint32_t*)b;
|
|
@@ -40,7 +40,7 @@ unsigned long start = printf_with_rtclock("begin merge(dst=%p, leftsrc=%p, Nleft
|
|
const T* rightend = args->rightsrc + args->Nright;
|
|
const T* rightend = args->rightsrc + args->Nright;
|
|
|
|
|
|
while (left != leftend && right != rightend) {
|
|
while (left != leftend && right != rightend) {
|
|
- if (compare<T>(left, right) < 0) {
|
|
|
|
|
|
+ if (compare_keys<T>(left, right) < 0) {
|
|
*dst = *left;
|
|
*dst = *left;
|
|
++dst;
|
|
++dst;
|
|
++left;
|
|
++left;
|
|
@@ -79,10 +79,10 @@ static size_t binsearch(const T* src, size_t len, const T* target)
|
|
if (len == 0) {
|
|
if (len == 0) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
- if (compare<T>(src + left, target) > 0) {
|
|
|
|
|
|
+ if (compare_keys<T>(src + left, target) > 0) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
- if (len > 0 && compare<T>(src + right - 1, target) < 0) {
|
|
|
|
|
|
+ if (len > 0 && compare_keys<T>(src + right - 1, target) < 0) {
|
|
return len;
|
|
return len;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -90,7 +90,7 @@ static size_t binsearch(const T* src, size_t len, const T* target)
|
|
// src[len] is considered to be greater than all targets)
|
|
// src[len] is considered to be greater than all targets)
|
|
while (right - left > 1) {
|
|
while (right - left > 1) {
|
|
size_t mid = left + (right - left)/2;
|
|
size_t mid = left + (right - left)/2;
|
|
- if (compare<T>(src + mid, target) > 0) {
|
|
|
|
|
|
+ if (compare_keys<T>(src + mid, target) > 0) {
|
|
right = mid;
|
|
right = mid;
|
|
} else {
|
|
} else {
|
|
left = mid;
|
|
left = mid;
|
|
@@ -201,7 +201,7 @@ bool mtmergesort(T* buf, size_t N, T* backing, threadid_t nthreads)
|
|
#ifdef PROFILE_MTMERGESORT
|
|
#ifdef PROFILE_MTMERGESORT
|
|
unsigned long start = printf_with_rtclock("begin qsort(buf=%p, N=%lu)\n", buf, N);
|
|
unsigned long start = printf_with_rtclock("begin qsort(buf=%p, N=%lu)\n", buf, N);
|
|
#endif
|
|
#endif
|
|
- qsort(buf, N, sizeof(T), compare<T>);
|
|
|
|
|
|
+ qsort(buf, N, sizeof(T), compare_keys<T>);
|
|
#ifdef PROFILE_MTMERGESORT
|
|
#ifdef PROFILE_MTMERGESORT
|
|
printf_with_rtclock_diff(start, "end qsort(buf=%p, N=%lu)\n", buf, N);
|
|
printf_with_rtclock_diff(start, "end qsort(buf=%p, N=%lu)\n", buf, N);
|
|
#endif
|
|
#endif
|