Order only what matters.
Compare the first key_size bytes while preserving every
byte of the enclosing record. Key and record lengths vary independently.
C++23 / fixed-width radix sort
bsort orders fixed-width binary records by a key prefix. Use it as a memory-mapped command-line tool or link the same engine into C++.
The useful constraint
General-purpose comparison sorts solve a larger problem. bsort uses the shape you already know—record width, key width, and byte alphabet— to keep partitioning work simple and record movement explicit.
Compare the first key_size bytes while preserving every
byte of the enclosing record. Key and record lengths vary independently.
Map and reorder one file directly, or read one mapping and write another. The library exposes the same choice for memory buffers.
Tuned radix cutoffs hand small buckets to cached-key cleanup sorts. Binary and printable-ASCII keys use independently measured defaults.
MSD radix engine
Histograms are reused across recursive passes. Record cycles move data in place, while small leaves switch to a keyed cleanup path rather than paying for another full radix level.
Validate the selected alphabet and count the current key byte in one pass.
Place records into byte buckets with bounded scratch storage and push-ahead cycles.
Continue on large buckets. Sort small leaves by cached keys and gather each record once.
One engine / two surfaces
Sort a file in place, or keep input and output separate. Printable ASCII keys use a compact 95-bucket specialization.
$ bsort -r 100 -k 8 records.bin $ bsort -a -i input.bin -o output.bin
Configure the record and key shape, then sort into a separate buffer—or pass the same pointer twice for in-place operation.
bsort::SortConfig config { .record_size = 100, .key_size = 8, }; bsort::sort_records(out, in, bytes, config);
Source release
The source archive includes the command-line tool, static library,
public header, tests, CMake package metadata, and the bsort(1)
manual page.
$ curl -LO https://bsort.goblinreactor.com/bsort.tar.gz $ tar -xzf bsort.tar.gz $ cd bsort $ ./configure --prefix=/usr/local $ make -j $ make check $ sudo make install