5 #define HeapSortDown(p, k, size, temp) \
9 if (s < size && p[s + 1] > p[s]) s++; \
10 if (temp >= p[s]) break; \
14 void HeapSort(UInt32
*p
, UInt32 size
)
25 HeapSortDown(p
, k
, size
, temp
)
33 UInt32 temp = p[size];
35 HeapSortDown(p, k, size, temp)
41 UInt32 temp
= p
[size
];
42 UInt32 k
= (p
[3] > p
[2]) ? 3 : 2;
45 HeapSortDown(p
, k
, size
, temp
)
48 UInt32 temp
= p
[size
];
50 if (size
> 2 && p
[2] < temp
)
61 #define HeapSortRefDown(p, vals, n, size, temp) \
62 { UInt32 k = n; UInt32 val = vals[temp]; for (;;) { \
63 UInt32 s = (k << 1); \
64 if (s > size) break; \
65 if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \
66 if (val >= vals[p[s]]) break; \
70 void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size)
80 HeapSortRefDown(p, vals, i, size, temp);
86 UInt32 temp = p[size];
88 HeapSortRefDown(p, vals, 1, size, temp);