36#if !defined(SAFEC_EXPORTS)
40template <
typename Sorter>
49 typedef typename Sorter::value
value;
56 void sort(
long lo,
long hi);
58 void sort2(
long lo,
long hi);
71 static void sort(Sorter *M0, value *elems0,
long len0);
79template <
typename Sorter>
91 while (
M->compare(
elems[j], pivot) < 0);
96 while (
M->compare(
elems[i], pivot) > 0);
109template <
typename Sorter>
126#define pivot_index() (begin + (end - begin) / 2)
127#define swap(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
129template <
typename Sorter>
144 if (
M->compare(
elems[l], pivot) <= 0)
151 M->compare(
elems[r], pivot) >=
168template <
typename Sorter>
184 if (
M->compare(
elems[l], pivot) <= 0)
191 M->compare(
elems[r], pivot) >=
218template <
typename Sorter>
224 unsigned long i, ir =
len, j, k, l = 1, *istack;
235 for (j = l + 1; j <= ir; j++)
238 for (i = j - 1; i >= l; i--)
241 if (
M->compare(
elems[i], a) <= 0)
break;
246 if (jstack == 0)
break;
247 ir = istack[jstack--];
248 l = istack[jstack--];
276 while (ncmps++,
M->compare(
elems[i], a) < 0);
279 while (ncmps++,
M->compare(
elems[j], a) > 0);
286 if (jstack > maxstack) maxstack = jstack;
289 fprintf(stderr,
"NSTACK too small in sort.\n");
292 if (ir - i + 1 >= j - l)
295 istack[jstack - 1] = i;
300 istack[jstack] = j - 1;
301 istack[jstack - 1] = l;
308 "quicksort: len = %ld ncmps = %ld 2*depth = %d\n",
321template <
typename Sorter>
324 unsigned long i, ir, j, l;
358 if (
M->compare(rra,
elems[j]) < 0)
369 fprintf(stderr,
"hpsort: %ld, %ld\n",
len, ncmps);
375template <
typename Sorter>
401 long double nsecs = end_time - begin_time;
402 nsecs /= CLOCKS_PER_SEC;
406 stderr,
"sort: len %ld depth %ld time %Lf\n", len0, S.
maxdepth, nsecs);
void sort(long lo, long hi)
void sort2depth(long lo, long hi, long depth)
QuickSorter(Sorter *M0, value *elems0, long len0)
long sort_partition(long lo, long hi)
void sort2(long lo, long hi)
Engine-to-interpreter type vocabulary across the C++ / .dd boundary.
#define newarray_atomic(T, len)
our_new_delete — per-class opt-in routing of new / delete through bdwgc.
TermIterator< Nterm > begin(Nterm *ptr)
TermIterator< Nterm > end(Nterm *)