1 /* A test of sorting routines */
4 #include "lib/getopt.h"
5 #include "lib/fastbuf.h"
16 static inline void s_write_merged(struct fastbuf *f, struct key **k, void **d, uns n, void *buf)
18 bwrite(f, k[0], sizeof(struct key));
22 static inline void s_copy_merged(struct key **keys, struct fastbuf **data, uns n, struct fastbuf *dest)
24 bwrite(dest, keys[0], sizeof(struct key));
25 bbcopy(data[0], dest, 5);
26 for (uns i=1; i<n; i++)
30 #define SORT_KEY_REGULAR struct key
31 #define SORT_PREFIX(x) s_##x
33 #define SORT_OUTPUT_FB
34 //#define SORT_KEY_SIZE(k) 4
35 #define SORT_DATA_SIZE(k) 5
38 #define SORT_INT(k) (k).x
40 #include "lib/sorter/sorter.h"
43 main(int argc, char **argv)
46 if (cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) >= 0 ||
49 fputs("This program supports only the following command-line arguments:\n" CF_USAGE, stderr);
53 log(L_INFO, "Generating");
54 struct fastbuf *f = bopen(argv[optind], O_RDWR | O_CREAT | O_TRUNC, 65536);
57 for (uns i=0; i<2*N; i++)
59 bputl(f, ((u64)i * K + 17) % N);
61 bputl(f, ((u64)i * K + 17) % N);
66 log(L_INFO, "Sorting");
67 f = s_sort(f, NULL, N-1);
69 log(L_INFO, "Verifying");
70 for (uns i=0; i<N; i++)
74 die("Discrepancy: %d instead of %d", j, i);
75 for (uns i='1'; i<='5'; i++)