1 /* Reads a 128 kB file into static data and "sorts" the bytes in
2 it, using counting sort, a single-pass algorithm. The sorted
3 data is written back to the same file in-place. */
8 #include "tests/main.h"
10 const char *test_name = "child-sort";
12 unsigned char buf[128 * 1024];
13 size_t histogram[256];
16 main (int argc UNUSED, char *argv[])
25 CHECK ((handle = open (argv[1])) > 1, "open \"%s\"", argv[1]);
27 size = read (handle, buf, sizeof buf);
28 for (i = 0; i < size; i++)
31 for (i = 0; i < sizeof histogram / sizeof *histogram; i++)
33 size_t j = histogram[i];
38 write (handle, buf, size);