11 #define heapify(_count) \ 13 for (int start = floor(((_count) - 2) / 2); start >= 0; --start) \ 15 siftdown(start, (_count) - 1); \ 19 #define siftdown(_start, _end) \ 21 for (int root = (_start); root * 2 + 1 <= (_end); ) \ 23 int child = root * 2 + 1; \ 24 if (child < (_end) && cmp(child, child + 1, pass) < 0) child += 1; \ 25 if (cmp(root, child, pass) >= 0) break; \ 26 swap(root, child, pass); \ 44 for (
int i = 1; i < n; ++i)
56 if (j != i) swap(j, i, pass);
int(int i1, int i2, entity pass) comparefunc_t
<0 for <, ==0 for ==, >0 for > (like strcmp)
ERASEABLE void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass)
ERASEABLE void shuffle(float n, swapfunc_t swap, entity pass)
#define siftdown(_start, _end)
void(int i1, int i2, entity pass) swapfunc_t
is only ever called for i1 < i2
#define pass(name, colormin, colormax)