MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / srt_heapsort

Function srt_heapsort

algorithm/algorithm.c:99–109  ·  view source on GitHub ↗

Heapsort — introsort's O(n log n) worst-case fallback. */

Source from the content-addressed store, hash-verified

97
98/* Heapsort — introsort's O(n log n) worst-case fallback. */
99static void srt_heapsort(char *base, size_t n, size_t size, CompareFunc comp, void *tmp) {
100 for (size_t i = n / 2; i > 0; ) {
101 --i;
102 srt_siftdown(base, i, n, size, comp, tmp);
103 }
104 for (size_t end = n; end > 1; ) {
105 --end;
106 swap(base, base + end * size, size);
107 srt_siftdown(base, 0, end, size, comp, tmp);
108 }
109}
110
111/* Median-of-3 Hoare quicksort, switching to insertion sort for small ranges and
112 * to heapsort once recursion gets too deep. Recurses on the smaller partition

Callers 1

srt_introsortFunction · 0.85

Calls 2

srt_siftdownFunction · 0.85
swapFunction · 0.85

Tested by

no test coverage detected