stdlib: Implement introsort for qsort (BZ 19305)
commit274a46c9b25ab733a1fb9fb1497f1beecae30193
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 3 Oct 2023 12:22:49 +0000 (3 09:22 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 31 Oct 2023 17:18:03 +0000 (31 14:18 -0300)
tree6bbc5910ee51e37f4dc0621b64554ae0a7e0db2d
parentd097f3c79be55d646d86efb7ce876bf84d5ebe4e
stdlib: Implement introsort for qsort (BZ 19305)

This patch makes the quicksort implementation to acts as introsort, to
avoid worse-case performance (and thus making it O(nlog n)).  It switch
to heapsort when the depth level reaches 2*log2(total elements).  The
heapsort is a textbook implementation.

Checked on x86_64-linux-gnu and aarch64-linux-gnu.
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
stdlib/qsort.c