1 /* A test of sorting routines */
4 #include "lib/getopt.h"
5 #include "lib/fastbuf.h"
16 #define SORT_KEY_REGULAR struct key
17 #define SORT_PREFIX(x) s_##x
19 #define SORT_OUTPUT_FB
20 #define SORT_INT(k) (k).x
22 #include "lib/sorter/sorter.h"
25 main(int argc, char **argv)
28 if (cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) >= 0 ||
31 fputs("This program supports only the following command-line arguments:\n" CF_USAGE, stderr);
35 log(L_INFO, "Generating");
36 struct fastbuf *f = bopen(argv[optind], O_RDWR | O_CREAT | O_TRUNC, 65536);
39 for (uns i=0; i<N; i++)
40 bputl(f, ((u64)i * K + 17) % N);
43 log(L_INFO, "Sorting");
44 f = s_sort(f, NULL, N-1);
46 log(L_INFO, "Verifying");
47 for (uns i=0; i<N; i++)
51 die("Discrepancy: %d instead of %d", j, i);