diff options
Diffstat (limited to 'src/lib/libc/stdlib/heapsort.c')
-rw-r--r-- | src/lib/libc/stdlib/heapsort.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/lib/libc/stdlib/heapsort.c b/src/lib/libc/stdlib/heapsort.c index bd998fa357..f4aeeef7a3 100644 --- a/src/lib/libc/stdlib/heapsort.c +++ b/src/lib/libc/stdlib/heapsort.c | |||
@@ -13,11 +13,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 15 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 16 | * 3. Neither the name of the University nor the names of its contributors |
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed by the University of | ||
19 | * California, Berkeley and its contributors. | ||
20 | * 4. Neither the name of the University nor the names of its contributors | ||
21 | * may be used to endorse or promote products derived from this software | 17 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 18 | * without specific prior written permission. |
23 | * | 19 | * |
@@ -35,8 +31,7 @@ | |||
35 | */ | 31 | */ |
36 | 32 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char sccsid[] = "from: @(#)heapsort.c 8.1 (Berkeley) 6/4/93";*/ | 34 | static char *rcsid = "$OpenBSD: heapsort.c,v 1.6 2003/09/08 16:24:05 deraadt Exp $"; |
39 | static char *rcsid = "$Id: heapsort.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 35 | #endif /* LIBC_SCCS and not lint */ |
41 | 36 | ||
42 | #include <sys/types.h> | 37 | #include <sys/types.h> |
@@ -73,7 +68,7 @@ static char *rcsid = "$Id: heapsort.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp | |||
73 | * Build the list into a heap, where a heap is defined such that for | 68 | * Build the list into a heap, where a heap is defined such that for |
74 | * the records K1 ... KN, Kj/2 >= Kj for 1 <= j/2 <= j <= N. | 69 | * the records K1 ... KN, Kj/2 >= Kj for 1 <= j/2 <= j <= N. |
75 | * | 70 | * |
76 | * There two cases. If j == nmemb, select largest of Ki and Kj. If | 71 | * There are two cases. If j == nmemb, select largest of Ki and Kj. If |
77 | * j < nmemb, select largest of Ki, Kj and Kj+1. | 72 | * j < nmemb, select largest of Ki, Kj and Kj+1. |
78 | */ | 73 | */ |
79 | #define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) { \ | 74 | #define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) { \ |
@@ -95,12 +90,12 @@ static char *rcsid = "$Id: heapsort.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp | |||
95 | * Select the top of the heap and 'heapify'. Since by far the most expensive | 90 | * Select the top of the heap and 'heapify'. Since by far the most expensive |
96 | * action is the call to the compar function, a considerable optimization | 91 | * action is the call to the compar function, a considerable optimization |
97 | * in the average case can be achieved due to the fact that k, the displaced | 92 | * in the average case can be achieved due to the fact that k, the displaced |
98 | * elememt, is ususally quite small, so it would be preferable to first | 93 | * element, is usually quite small, so it would be preferable to first |
99 | * heapify, always maintaining the invariant that the larger child is copied | 94 | * heapify, always maintaining the invariant that the larger child is copied |
100 | * over its parent's record. | 95 | * over its parent's record. |
101 | * | 96 | * |
102 | * Then, starting from the *bottom* of the heap, finding k's correct place, | 97 | * Then, starting from the *bottom* of the heap, finding k's correct place, |
103 | * again maintianing the invariant. As a result of the invariant no element | 98 | * again maintaining the invariant. As a result of the invariant no element |
104 | * is 'lost' when k is assigned its correct place in the heap. | 99 | * is 'lost' when k is assigned its correct place in the heap. |
105 | * | 100 | * |
106 | * The time savings from this optimization are on the order of 15-20% for the | 101 | * The time savings from this optimization are on the order of 15-20% for the |
@@ -142,7 +137,7 @@ int | |||
142 | heapsort(vbase, nmemb, size, compar) | 137 | heapsort(vbase, nmemb, size, compar) |
143 | void *vbase; | 138 | void *vbase; |
144 | size_t nmemb, size; | 139 | size_t nmemb, size; |
145 | int (*compar) __P((const void *, const void *)); | 140 | int (*compar)(const void *, const void *); |
146 | { | 141 | { |
147 | register int cnt, i, j, l; | 142 | register int cnt, i, j, l; |
148 | register char tmp, *tmp1, *tmp2; | 143 | register char tmp, *tmp1, *tmp2; |