To make developers think carefully through the use of this function
under FreeBSD, until further.
MFC after: 1 week
Sponsored by: NVIDIA Networking
Differential D39723
Add a compile time warning for qsort() about issues regarding execution time. • hselasky on Apr 20 2023, 5:39 PM. Authored by Tags None Referenced Files
Details
Diff Detail
Event TimelineComment Actions https://codesearch.debian.net/search?q=%5Cbqsort%5C%28&literal=0 - 13393 files grepped (16892 results) Comment Actions The ISO C standard does not mandate any kind of performance nor implementation. So why not state that? It doesn't look apparent to me FreeBSD developers know about this, when you grep through the FreeBSD sources: freebsd-src % find . -name "*.[ch]" | xargs grep qsort | wc -l 600 freebsd-src % find . -name "*.[ch]" | xargs grep mergesort | wc -l 46 freebsd-src % find . -name "*.[ch]" | xargs grep heapsort | wc -l 34 freebsd-src % find . -name "*.[ch]" | xargs grep radixsort | wc -l 12 freebsd-src % As long as qsort() is implemented like it is in libc it should be warned about or stated somewhere obvious. --HPS Comment Actions It's legal to implement malloc as sleep(UINT_MAX); /* actual malloc code */ per ISO C's specification, or any other standard function for that matter. Everyone understands that implementations should be efficient where reasonable. You're just being obtuse here at this point. I have no interest in furthering this inane discussion. Comment Actions I have to admit that I get bitten by the function name. I almost always treat qsort() as quicksort but it is actually a generic interface for sorting. A second thought about this, I think for STD C or POSIX, use an implementation as standard is not scalable, as there're so many sorting algorithms. From qsort(3):
Regardless of the naming, maybe it is right direction to place emphasis about the standard / posix requirement of qsort(). What do you all think ? Comment Actions @zlei : ISO C apparently on defines one standard sorting function, and it is named qsort(), and the definition of performance is very loose. @zlei : I'm doing some research if a pre-step for QuickSort, may be a solution to completely avoid QuickSort going O(N*N). If you want to join, let me know. Maybe I can put something up on GitHub. --HPS |