Generic quicksort library that can be used to sort an array having any data type (int, char *, struct key_value *, etc.).

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Fri Sep 26 16:57:49 GMT 2025



On 26/09/25 17:37, Collin Funk wrote:
> Amit <amitchoudhary0523@gmail.com> writes:
> 
>> This is misleading. It is mergesort. It should have been called msort().
>>
>> Then there is one more issue - if memory allocation fails then it does
>> "heapsort".
>>
>> But no quicksort out there.
> 
> There is no requirement that qsort uses quicksort. POSIX only requires
> that it sorts the elements [1].
> 
> Collin
> 
> [1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/qsort.html

Also check 03bf8357e8291857a435afcc3048e0b697b6cc04 why we changed to use use
introsort and 709fbd3ec3595f2d1076b4fec09a739327459288 for why we had to
reinstate the use of mergesort.

And taking the swap function from user is not necessary the best solution,
for small elements the indirect function will most likely dominate. And 
it will require changing the ABI, which will require a new symbol.

I think for qsort and alike function (like bsearch) it would be better to
use something like the BZ#17941 proposal [1]. But it also all the associate
quirks when you try to emulate meta-programming with C (code bloat and type
safeness requires a bunch of macros like we to for dynarray).

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=17941


More information about the Libc-alpha mailing list