X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fsort.qh;h=cd0000912dfcfb65b715bcfabebf889d29144adc;hb=7892e4aee4861fcc8191a3f0890293665b9c7abd;hp=748bd2b2748efe82a071e4583771adbe338de146;hpb=c741e6b3f012aa525f23e1df30d1d933b383fbc5;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/sort.qh b/qcsrc/lib/sort.qh index 748bd2b27..cd0000912 100644 --- a/qcsrc/lib/sort.qh +++ b/qcsrc/lib/sort.qh @@ -1,26 +1,23 @@ -#ifndef SORT_H -#define SORT_H +#pragma once /** is only ever called for i1 < i2 */ -typedef void (int i1, int i2, entity pass) swapfunc_t; +USING(swapfunc_t, void (int i1, int i2, entity pass)); /** <0 for <, ==0 for ==, >0 for > (like strcmp) */ -typedef int (int i1, int i2, entity pass) comparefunc_t; +USING(comparefunc_t, int (int i1, int i2, entity pass)); +ERASEABLE void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass) { #define heapify(_count) \ - do \ - { \ + MACRO_BEGIN \ for (int start = floor(((_count) - 2) / 2); start >= 0; --start) \ { \ siftdown(start, (_count) - 1); \ } \ - } \ - while (0) + MACRO_END #define siftdown(_start, _end) \ - do \ - { \ + MACRO_BEGIN \ for (int root = (_start); root * 2 + 1 <= (_end); ) \ { \ int child = root * 2 + 1; \ @@ -29,8 +26,7 @@ void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass) swap(root, child, pass); \ root = child; \ } \ - } \ - while (0) + MACRO_END heapify(n); int end = n - 1; @@ -42,6 +38,7 @@ void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass) } } +ERASEABLE void shuffle(float n, swapfunc_t swap, entity pass) { for (int i = 1; i < n; ++i) @@ -59,5 +56,3 @@ void shuffle(float n, swapfunc_t swap, entity pass) if (j != i) swap(j, i, pass); } } - -#endif