Commit graph

5 commits

Author SHA1 Message Date
Emil Renner Berthing
194f9cf93d stdlib: add qsort_r 2014-09-19 19:43:23 +02:00
Rich Felker
1477a3be62 avoid crashing when nel==0 is passed to qsort 2011-04-29 11:14:55 -04:00
Rich Felker
22263709ed replace heap sort with smoothsort implementation by Valentin Ochs
Smoothsort is an adaptive variant of heapsort. This version was
written by Valentin Ochs (apo) specifically for inclusion in musl. I
worked with him to get it working in O(1) memory usage even with giant
array element widths, and to optimize it heavily for size and speed.
It's still roughly 4 times as large as the old heap sort
implementation, but roughly 20 times faster given an almost-sorted
array of 1M elements (20 being the base-2 log of 1M), i.e. it really
does reduce O(n log n) to O(n) in the mostly-sorted case. It's still
somewhat slower than glibc's Introsort for random input, but now
considerably faster than glibc when the input is already sorted, or
mostly sorted.
2011-04-27 13:27:04 -04:00
Rich Felker
b24bc15f5c don't compare elements with themselves during qsort.
this is actually a workaround for a bug in gcc, whereby it asserts
inequality of the keys being compared...
2011-02-17 00:03:24 -05:00
Rich Felker
0b44a0315b initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00