Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/sort: fix outdated comment regarding glibc qsort()

The existing comment in lib/sort refers to glibc qsort() using quicksort.
However, glibc qsort() no longer uses quicksort; it now uses mergesort and
falls back to heapsort if memory allocation for mergesort fails. This
makes the comment outdated and incorrect.

Update the comment to refer to quicksort in general rather than glibc's
implementation to provide accurate information about the comparisons and
trade-offs without implying an outdated implementation.

Link: https://lkml.kernel.org/r/20240527203011.1644280-3-visitorckw@gmail.com
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kuan-Wei Chiu and committed by
Andrew Morton
f49ac957 85fb11a8

+1 -1
+1 -1
lib/sort.c
··· 5 5 * This performs n*log2(n) + 0.37*n + o(n) comparisons on average, 6 6 * and 1.5*n*log2(n) + O(n) in the (very contrived) worst case. 7 7 * 8 - * Glibc qsort() manages n*log2(n) - 1.26*n for random inputs (1.63*n 8 + * Quicksort manages n*log2(n) - 1.26*n for random inputs (1.63*n 9 9 * better) at the expense of stack usage and much larger code to avoid 10 10 * quicksort's O(n^2) worst case. 11 11 */