44 int (*qcmp) (
const void *,
const void *);
47 static void qst (
qst_t * q,
char *base,
char *max);
57 int (*compar) (
const void *,
const void *))
75 max = base + n * q->
qsz;
91 for (j = lo = base; (lo += q->
qsz) < hi;)
93 if ((*compar) (j,
lo) > 0)
98 for (i = base, hi = base + q->
qsz; i < hi;)
112 for (min = base; (hi = min += q->
qsz) < max;)
114 while ((*q->
qcmp) (hi -= q->
qsz, min) > 0);
115 if ((hi += q->
qsz) != min)
117 for (lo = min + q->
qsz; --lo >= min;)
120 for (i = j = lo; (j -= q->
qsz) >= hi; i = j)
158 lo = (int) (max - base);
170 mid = i = base + qsz * ((unsigned) (lo / qsz) >> 1);
173 j = ((*q->
qcmp) ((jj = base),
i) > 0 ? jj : i);
174 if ((*q->
qcmp) (j, (tmp = max - qsz)) > 0)
177 j = (j == jj ? i : jj);
178 if ((*q->
qcmp) (j, tmp) < 0)
194 for (i = base, j = max - qsz;;)
196 while (i < mid && (*q->
qcmp) (
i, mid) <= 0)
200 if ((*q->
qcmp) (mid, j) <= 0)
246 if ((lo = (
int) (j - base)) <= (hi = (int) (max - i)))
static void qst(qst_t *q, char *base, char *max)
int(* qcmp)(const void *, const void *)
void qsort(void *base, uword n, uword size, int(*compar)(const void *, const void *))