Imported Upstream version 0.6.27
[platform/upstream/libsolv.git] / src / qsort_r.c
index 7911ec5..d49049a 100644 (file)
@@ -3,6 +3,8 @@
  * argument ordering
  */
 
+/* FIXME: should use mergesort instead */
+
 /*-
  * Copyright (c) 1992, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -45,7 +47,9 @@ typedef int            cmp_t(const void *, const void *, void *);
 static inline char     *med3(char *, char *, char *, cmp_t *, void *);
 static inline void      swapfunc(char *, char *, int, int);
 
+#ifndef min
 #define min(a, b)      (a) < (b) ? a : b
+#endif
 
 /*
  * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
@@ -96,7 +100,7 @@ med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk)
 }
 
 void
-sat_sort(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk)
+solv_sort(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk)
 {
        char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
        size_t d, r;
@@ -107,7 +111,7 @@ loop:       SWAPINIT(a, es);
        swap_cnt = 0;
        if (n < 7) {
                for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
-                       for (pl = pm; 
+                       for (pl = pm;
                             pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
                             pl -= es)
                                swap(pl, pl - es);
@@ -155,7 +159,7 @@ loop:       SWAPINIT(a, es);
        }
        if (swap_cnt == 0) {  /* Switch to insertion sort */
                for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
-                       for (pl = pm; 
+                       for (pl = pm;
                             pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
                             pl -= es)
                                swap(pl, pl - es);
@@ -168,7 +172,7 @@ loop:       SWAPINIT(a, es);
        r = min(pd - pc, pn - pd - es);
        vecswap(pb, pn - r, r);
        if ((r = pb - pa) > es)
-               sat_sort(a, r / es, es, cmp, thunk);
+               solv_sort(a, r / es, es, cmp, thunk);
        if ((r = pd - pc) > es) {
                /* Iterate rather than recurse to save stack space */
                a = pn - r;