X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=debug%2Fsorter%2Fretros.c;h=7bb692f6bead3094d3d3b06a6ea8a9088d3a0042;hb=6cbd32307057f98fc793eaf9dc97c99c62a85a43;hp=073cd8b078e32c94174494ccada181af56d97671;hpb=6653d0a752dd937152fa66f1725fab42edc25b8a;p=libucw.git diff --git a/debug/sorter/retros.c b/debug/sorter/retros.c index 073cd8b0..7bb692f6 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 @@ -50,13 +51,13 @@ static int comp_ind(const void *x, const void *y) #define ASORT_ELT(i) a[i].key #define ASORT_SWAP(i,j) do { struct elt t=a[i]; a[i]=a[j]; a[j]=t; } while (0) #define ASORT_EXTRA_ARGS , struct elt *a -#include "ucw/arraysort.h" +#include "ucw/sorter/array-simple.h" #define ASORT_PREFIX(x) asi_##x #define ASORT_KEY_TYPE u32 #define ASORT_ELT(i) ind[i]->key #define ASORT_SWAP(i,j) do { struct elt *t=ind[i]; ind[i]=ind[j]; ind[j]=t; } while (0) -#include "ucw/arraysort.h" +#include "ucw/sorter/array-simple.h" static void r1_sort(void) { @@ -614,12 +615,34 @@ 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; alt = array1; - struct MD5Context ctx; - MD5Init(&ctx); + md5_context ctx; + md5_init(&ctx); u32 block[16]; bzero(block, sizeof(block)); @@ -630,7 +653,7 @@ static void mk_ary(void) if (!(i % 4)) { block[i%16] = i; - MD5Transform(ctx.buf, block); + md5_transform(ctx.buf, block); } ary[i].key = ctx.buf[i%4]; #else @@ -696,6 +719,8 @@ int main(int argc, char **argv) for (uns i=0; i