X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=debug%2Fsorter%2Fretros.c;h=0d417bab48429488ef85494ab95ebb99588ab0f5;hb=09e7fe5641b94148d998a1b620bf694f353cb17b;hp=ea6de037ea0ddf662bd8e8d0123797e80f79f1f5;hpb=ccf0d79b2a55614e40afc6ad6dff231a86df4a70;p=libucw.git diff --git a/debug/sorter/retros.c b/debug/sorter/retros.c index ea6de037..0d417bab 100644 --- a/debug/sorter/retros.c +++ b/debug/sorter/retros.c @@ -1,12 +1,13 @@ /* * Experiments with various sorting algorithms * - * (c) 2007 Martin Mares + * (c) 2007--2008 Martin Mares */ #include "sherlock/sherlock.h" #include "ucw/getopt.h" #include "ucw/md5.h" +#include "ucw/heap.h" #include #include @@ -614,6 +615,28 @@ static void samplesort2(void) xfree(aux); } +static void heapsort(void) +{ +#define H_LESS(_a,_b) ((_a).key > (_b).key) + struct elt *heap = ary-1; + HEAP_INIT(struct elt, heap, n, H_LESS, HEAP_SWAP); + uns nn = n; + while (nn) + HEAP_DELMIN(struct elt, heap, nn, H_LESS, HEAP_SWAP); +#undef H_LESS +} + +static void heapsort_ind(void) +{ +#define H_LESS(_a,_b) ((_a)->key > (_b)->key) + struct elt **heap = ind-1; + HEAP_INIT(struct elt *, heap, n, H_LESS, HEAP_SWAP); + uns nn = n; + while (nn) + HEAP_DELMIN(struct elt *, heap, nn, H_LESS, HEAP_SWAP); +#undef H_LESS +} + static void mk_ary(void) { ary = array0; @@ -696,6 +719,8 @@ int main(int argc, char **argv) for (uns i=0; i