diff options
Diffstat (limited to 'main/mergesort.c')
-rw-r--r-- | main/mergesort.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/main/mergesort.c b/main/mergesort.c index b049e683a9..a482f5b0fe 100644 --- a/main/mergesort.c +++ b/main/mergesort.c @@ -66,8 +66,8 @@ static char sccsid[] = "@(#)merge.c 8.2 (Berkeley) 2/14/94"; #include <winsock2.h> /* Includes definition for u_char */ #endif -static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); -static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); +static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void *)); +static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void *)); #define ISIZE sizeof(int) #define PSIZE sizeof(u_char *) @@ -102,7 +102,7 @@ static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const voi /* {{{ php_mergesort * Arguments are as for qsort. */ -PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) +PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) { register size_t i; register int sense; @@ -130,7 +130,7 @@ PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const return (-1); list1 = base; - setup(list1, list2, nmemb, size, cmp TSRMLS_CC); + setup(list1, list2, nmemb, size, cmp); last = list2 + nmemb * size; i = big = 0; while (*EVAL(list2) != last) { @@ -144,7 +144,7 @@ PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const p2 = *EVAL(p2); l2 = list1 + (p2 - list2); while (f1 < l1 && f2 < l2) { - if ((*cmp)(f1, f2 TSRMLS_CC) <= 0) { + if ((*cmp)(f1, f2) <= 0) { q = f2; b = f1, t = l1; sense = -1; @@ -154,7 +154,7 @@ PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const sense = 0; } if (!big) { /* here i = 0 */ - while ((b += size) < t && cmp(q, b TSRMLS_CC) >sense) + while ((b += size) < t && cmp(q, b) >sense) if (++i == 6) { big = 1; goto EXPONENTIAL; @@ -163,12 +163,12 @@ PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const EXPONENTIAL: for (i = size; ; i <<= 1) if ((p = (b + i)) >= t) { if ((p = t - size) > b && - (*cmp)(q, p TSRMLS_CC) <= sense) + (*cmp)(q, p) <= sense) t = p; else b = p; break; - } else if ((*cmp)(q, p TSRMLS_CC) <= sense) { + } else if ((*cmp)(q, p) <= sense) { t = p; if (i == size) big = 0; @@ -177,7 +177,7 @@ EXPONENTIAL: for (i = size; ; i <<= 1) b = p; while (t > b+size) { i = (((t - b) / size) >> 1) * size; - if ((*cmp)(q, p = b + i TSRMLS_CC) <= sense) + if ((*cmp)(q, p = b + i) <= sense) t = p; else b = p; @@ -185,7 +185,7 @@ EXPONENTIAL: for (i = size; ; i <<= 1) goto COPY; FASTCASE: while (i > size) if ((*cmp)(q, - p = b + (i >>= 1) TSRMLS_CC) <= sense) + p = b + (i >>= 1)) <= sense) t = p; else b = p; @@ -262,14 +262,14 @@ COPY: b = t; * when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL * is defined. Otherwise simple pairwise merging is used.) */ -static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) +static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void *)) { size_t i, length, size2, sense; u_char *f1, *f2, *s, *l2, *last, *p2, tmp; size2 = size*2; if (n <= 5) { - insertionsort(list1, n, size, cmp TSRMLS_CC); + insertionsort(list1, n, size, cmp); *EVAL(list2) = (u_char*) list2 + n*size; return; } @@ -278,19 +278,19 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp * for simplicity. */ i = 4 + (n & 1); - insertionsort(list1 + (n - i) * size, i, size, cmp TSRMLS_CC); + insertionsort(list1 + (n - i) * size, i, size, cmp); last = list1 + size * (n - i); *EVAL(list2 + (last - list1)) = list2 + n * size; #ifdef NATURAL p2 = list2; f1 = list1; - sense = (cmp(f1, f1 + size TSRMLS_CC) > 0); + sense = (cmp(f1, f1 + size) > 0); for (; f1 < last; sense = !sense) { length = 2; /* Find pairs with same sense. */ for (f2 = f1 + size2; f2 < last; f2 += size2) { - if ((cmp(f2, f2+ size TSRMLS_CC) > 0) != sense) + if ((cmp(f2, f2+ size) > 0) != sense) break; length += 2; } @@ -303,7 +303,7 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp } else { /* Natural merge */ l2 = f2; for (f2 = f1 + size2; f2 < l2; f2 += size2) { - if ((cmp(f2-size, f2 TSRMLS_CC) > 0) != sense) { + if ((cmp(f2-size, f2) > 0) != sense) { p2 = *EVAL(p2) = f2 - list1 + list2; if (sense > 0) reverse(f1, f2-size); @@ -313,7 +313,7 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp if (sense > 0) reverse (f1, f2-size); f1 = f2; - if (f2 < last || cmp(f2 - size, f2 TSRMLS_CC) > 0) + if (f2 < last || cmp(f2 - size, f2) > 0) p2 = *EVAL(p2) = f2 - list1 + list2; else p2 = *EVAL(p2) = list2 + n*size; @@ -322,7 +322,7 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp #else /* pairwise merge only. */ for (f1 = list1, p2 = list2; f1 < last; f1 += size2) { p2 = *EVAL(p2) = p2 + size2; - if (cmp (f1, f1 + size TSRMLS_CC) > 0) + if (cmp (f1, f1 + size) > 0) swap(f1, f1 + size); } #endif /* NATURAL */ @@ -333,7 +333,7 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp * This is to avoid out-of-bounds addresses in sorting the * last 4 elements. */ -static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) +static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void *)) { u_char *ai, *s, *t, *u, tmp; size_t i; @@ -341,7 +341,7 @@ static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const voi for (ai = a+size; --n >= 1; ai += size) for (t = ai; t > a; t -= size) { u = t - size; - if (cmp(u, t TSRMLS_CC) <= 0) + if (cmp(u, t) <= 0) break; swap(u, t); } |