summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/heapsort.c
diff options
context:
space:
mode:
authormillert <>2017-05-20 12:48:56 +0000
committermillert <>2017-05-20 12:48:56 +0000
commit78fdfc7b710f4922d56e067d044f7f7087c0872e (patch)
tree70cacb19950e1b5c46c66a865398a84d600761f5 /src/lib/libc/stdlib/heapsort.c
parentabfa5942eee63f49119ddd016cb3f95b77b7c16b (diff)
downloadopenbsd-78fdfc7b710f4922d56e067d044f7f7087c0872e.tar.gz
openbsd-78fdfc7b710f4922d56e067d044f7f7087c0872e.tar.bz2
openbsd-78fdfc7b710f4922d56e067d044f7f7087c0872e.zip
Use David Musser's introsort algorithm to fall back to heapsort(3)
when the recursion depth reaches 2*lg(n + 1). This avoids quicksort's quadratic behavior for pathological input without appreciably changing the average run time.
Diffstat (limited to 'src/lib/libc/stdlib/heapsort.c')
-rw-r--r--src/lib/libc/stdlib/heapsort.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/lib/libc/stdlib/heapsort.c b/src/lib/libc/stdlib/heapsort.c
index 878567729e..f1db2205b0 100644
--- a/src/lib/libc/stdlib/heapsort.c
+++ b/src/lib/libc/stdlib/heapsort.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: heapsort.c,v 1.10 2016/10/22 19:19:34 tb Exp $ */ 1/* $OpenBSD: heapsort.c,v 1.11 2017/05/20 12:48:56 millert Exp $ */
2/*- 2/*-
3 * Copyright (c) 1991, 1993 3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved. 4 * The Regents of the University of California. All rights reserved.
@@ -172,3 +172,4 @@ heapsort(void *vbase, size_t nmemb, size_t size,
172 free(k); 172 free(k);
173 return (0); 173 return (0);
174} 174}
175DEF_WEAK(heapsort);