32 typedef unsigned long long int Uint64;
47 #pragma global noalias 50 #pragma cdir options -pvctl,nodep 52 #pragma cdir options -pvctl,nodep 55 typedef long long int ll_t;
57 #define ALLOC(x,size) \ 58 { ll_t bytes = (ll_t)sizeof(*x) * (size); \ 59 bytes = (bytes < 1) ? 1 : bytes; \ 60 x = THEmalloc(bytes); \ 61 if (!x) { fprintf(stderr, \ 62 "malloc() of %s (%lld bytes) failed in file=%s, line=%d\n", \ 63 #x, bytes, __FILE__, __LINE__); RAISE(SIGABRT); } } 65 #define FREE(x) if (x) { THEfree(x); x = NULL; } 67 #if defined(NO_TRUNC) || defined(VPP) || defined(NECSX) 69 #define trunc(x) ((x) - fmod((x),1)) 71 extern double trunc(
double d);
74 #define MakeKwikSort(T) \ 82 T##cmp(const T##Str_t *a, const T##Str_t *b) { \ 83 if ( *a->valueptr > *b->valueptr ) return 1; \ 84 else if ( *a->valueptr < *b->valueptr ) return -1; \ 87 return (a->j > b->j) ? 1 : -1; \ 91 T##cmp_rev(const T##Str_t *a, const T##Str_t *b) { \ 92 if ( *a->valueptr < *b->valueptr ) return 1; \ 93 else if ( *a->valueptr > *b->valueptr ) return -1; \ 96 return (a->j > b->j) ? 1 : -1; \ 101 kwiksort_##T(const T v[], int n, int index[], int inc, \ 102 int index_adj, int mode, int irev) \ 105 T##Str_t *x = NULL; \ 110 for (j=0; j<n; j++) { x[j].valueptr = &v[j]; \ 112 x[j].idx = j + index_adj; \ 116 for (j=0; j<n; j++) { x[j].valueptr = &v[j * inc]; \ 118 x[j].idx = j + index_adj; \ 124 for (j=0; j<n; j++) { \ 125 int tmpidx = index[j] - index_adj; \ 126 x[j].valueptr = &v[tmpidx]; \ 128 x[j].idx = index[j]; \ 132 for (j=0; j<n; j++) { \ 133 int tmpidx = index[j] - index_adj; \ 134 x[j].valueptr = &v[tmpidx * inc]; \ 136 x[j].idx = index[j]; \ 140 qsort(x, n, sizeof(*x), \ 142 (int (*)(const void *, const void *))T##cmp_rev : \ 143 (int (*)(const void *, const void *))T##cmp); \ 144 for (j=0; j<n; j++) index[j] = x[j].idx; \ 148 #define MakeFastSort(T) \ 150 T##fcmp(const T *a, const T *b) { \ 151 if ( *a > *b ) return 1; \ 152 else if ( *a < *b ) return -1; \ 156 T##fcmp_rev(const T *a, const T *b) { \ 157 if ( *a < *b ) return 1; \ 158 else if ( *a > *b ) return -1; \ 163 FastSort_##T(T v[], int n, int irev) \ 165 qsort(v, n, sizeof(*v), \ 167 (int (*)(const void *, const void *))T##fcmp_rev : \ 168 (int (*)(const void *, const void *))T##fcmp); \ 171 #define kwiksort(T) \ 193 #define DoSort(T) { \ 196 kwiksort_##T(&data[addr], n, index, inc, index_adj, mode, irev); \ 200 #define DoFastSort(T) { \ 203 FastSort_##T(data, n, irev); \ 211 const int *Start_addr,
214 const int *Index_adj,
223 int index_adj = *Index_adj;
225 int addr = (*Start_addr) - 1;
227 if (method != SORT_UINT &&
228 method != SORT_INT &&
229 method != SORT_R64 &&
230 method != SORT_R32 &&
231 method != SORT_I64 &&
232 method != SORT_U64 ) {
286 if (method != SORT_UINT &&
287 method != SORT_INT &&
288 method != SORT_R64 &&
289 method != SORT_R32 &&
290 method != SORT_I64 &&
291 method != SORT_U64 ) {
327 #define MakeMergeFuncs(T) \ 329 T##_Merge(T data[], int amax, int bmax) \ 331 int i, j, N = amax + bmax; \ 333 T *b = &data[amax]; \ 339 memcpy(c, b, bmax * sizeof(T)); \ 341 while ((i >= 0) && (k >= 0)) { \ 342 if (a[i] >= c[k]) data[j--] = a[i--]; else data[j--] = c[k--]; \ 344 while (k >= 0) data[j--] = c[k--]; \ 350 T##_MergeIdx(const T data[], int amax, int bmax, int index[], const int rank[]) \ 352 int i, j, N = amax + bmax; \ 354 int *b = &index[amax]; \ 356 if (data[a[i]] > data[b[0]]) { \ 360 memcpy(c, b, bmax * sizeof(int)); \ 362 while ((i >= 0) && (k >= 0)) { \ 363 T dai = data[a[i]]; \ 364 T dck = data[c[k]]; \ 365 if (dai > dck) index[j--] = a[i--]; \ 366 else if (dai < dck) index[j--] = c[k--]; \ 368 if (rank[a[i]] > rank[c[k]]) index[j--] = a[i--]; else index[j--] = c[k--]; \ 371 while (k >= 0) index[j--] = c[k--]; \ 377 T##_Merge_rev(T data[], int amax, int bmax) \ 379 int i, j, N = amax + bmax; \ 381 T *b = &data[amax]; \ 387 memcpy(c, b, bmax * sizeof(T)); \ 389 while ((i >= 0) && (k >= 0)) { \ 390 if (a[i] <= c[k]) data[j--] = a[i--]; else data[j--] = c[k--]; \ 392 while (k >= 0) data[j--] = c[k--]; \ 398 T##_MergeIdx_rev(const T data[], int amax, int bmax, int index[], const int rank[]) \ 400 int i, j, N = amax + bmax; \ 402 int *b = &index[amax]; \ 404 if (data[a[i]] < data[b[0]]) { \ 408 memcpy(c, b, bmax * sizeof(int)); \ 410 while ((i >= 0) && (k >= 0)) { \ 411 T dai = data[a[i]]; \ 412 T dck = data[c[k]]; \ 413 if (dai < dck) index[j--] = a[i--]; \ 414 else if (dai > dck) index[j--] = c[k--]; \ 416 if (rank[a[i]] > rank[c[k]]) index[j--] = a[i--]; else index[j--] = c[k--]; \ 419 while (k >= 0) index[j--] = c[k--]; \ 432 #define DoMerge(T) { \ 435 if (index && nidx >= n) { \ 437 if (index_adj) for (j=0; j<n; j++) index[j] -= index_adj; \ 439 T##_MergeIdx_rev(X, amax, bmax, index, rank) : \ 440 T##_MergeIdx(X, amax, bmax, index, rank); \ 441 if (index_adj) for (j=0; j<n; j++) index[j] += index_adj; \ 444 rc = irev ? T##_Merge_rev(X, amax, bmax) : T##_Merge(X, amax, bmax); \ 449 const int *Start_addr,
455 const int *Index_adj,
462 int addr = (*Start_addr) - 1;
467 int index_adj = *Index_adj;
471 if (method != SORT_UINT &&
472 method != SORT_INT &&
473 method != SORT_R64 &&
474 method != SORT_R32 &&
475 method != SORT_I64 &&
476 method != SORT_U64 ) {
void ecqsort_(const int *Mode, const int *N, const int *Inc, const int *Start_addr, void *Data, int index[], const int *Index_adj, const int *Reverse, int *retc)
unsigned long long int Uint64
void ecmerge2_(const int *Mode, const int *Start_addr, const int *Amax, const int *Bmax, void *Data, int *index, const int *Nidx, const int *Index_adj, const int *Reverse, const int rank[], int *retc)
integer(kind=kindofint) nidx
void ecqsortfast_(const int *Mode, const int *N, void *Data, const int *Reverse, int *retc)
unsigned long long int Uint64