qsort.c (6875d25465631b7563f1b90e6b05e2640dc81f4e) qsort.c (c1087c13240442926a34afa825b4dd3993868549)
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * $Id$
33 * $Id: qsort.c,v 1.7 1997/02/22 09:39:58 peter Exp $
34 */
35
36#include <stdlib.h>
37
38typedef int cmp_t __P((const void *, const void *));
34 */
35
36#include <stdlib.h>
37
38typedef int cmp_t __P((const void *, const void *));
39static inline char *med3 __P((char *, char *, char *, cmp_t *));
40static inline void swapfunc __P((char *, char *, int, int));
39static __inline char *med3 __P((char *, char *, char *, cmp_t *));
40static __inline void swapfunc __P((char *, char *, int, int));
41
42#define min(a, b) (a) < (b) ? a : b
43
44/*
45 * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
46 */
47#define swapcode(TYPE, parmi, parmj, n) { \
48 long i = (n) / sizeof (TYPE); \

--- 4 unchanged lines hidden (view full) ---

53 *pi++ = *pj; \
54 *pj++ = t; \
55 } while (--i > 0); \
56}
57
58#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
59 es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
60
41
42#define min(a, b) (a) < (b) ? a : b
43
44/*
45 * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
46 */
47#define swapcode(TYPE, parmi, parmj, n) { \
48 long i = (n) / sizeof (TYPE); \

--- 4 unchanged lines hidden (view full) ---

53 *pi++ = *pj; \
54 *pj++ = t; \
55 } while (--i > 0); \
56}
57
58#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
59 es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
60
61static inline void
61static __inline void
62swapfunc(a, b, n, swaptype)
63 char *a, *b;
64 int n, swaptype;
65{
66 if(swaptype <= 1)
67 swapcode(long, a, b, n)
68 else
69 swapcode(char, a, b, n)

--- 4 unchanged lines hidden (view full) ---

74 long t = *(long *)(a); \
75 *(long *)(a) = *(long *)(b); \
76 *(long *)(b) = t; \
77 } else \
78 swapfunc(a, b, es, swaptype)
79
80#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
81
62swapfunc(a, b, n, swaptype)
63 char *a, *b;
64 int n, swaptype;
65{
66 if(swaptype <= 1)
67 swapcode(long, a, b, n)
68 else
69 swapcode(char, a, b, n)

--- 4 unchanged lines hidden (view full) ---

74 long t = *(long *)(a); \
75 *(long *)(a) = *(long *)(b); \
76 *(long *)(b) = t; \
77 } else \
78 swapfunc(a, b, es, swaptype)
79
80#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
81
82static inline char *
82static __inline char *
83med3(a, b, c, cmp)
84 char *a, *b, *c;
85 cmp_t *cmp;
86{
87 return cmp(a, b) < 0 ?
88 (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
89 :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
90}

--- 82 unchanged lines hidden ---
83med3(a, b, c, cmp)
84 char *a, *b, *c;
85 cmp_t *cmp;
86{
87 return cmp(a, b) < 0 ?
88 (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
89 :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
90}

--- 82 unchanged lines hidden ---