Skip to content

chemoelectric/integer-radix-sort

Repository files navigation

Integer-keyed stable radix sort for C
-------------------------------------

This sort tends to much faster than qsort(3), and is stable. However,
the keys must belong to one of the C compiler’s integer types.

The ‘radix’ for the sort is 256. In other words, the sorting is done
one byte position at a time.

This package is a translation into C macros of a similar sort I wrote
as ATS2 template functions.

There are also pre-compiled sort functions for many different integer
types. These sort functions resemble qsort(3) but take a ‘get_key’
function instead of a ‘comparison’ function. Also, the ‘get_key’
parameter can be set to NULL, in which case the array entry is used as
its own key.

You have to have an m4 implementation to build the package. You can
use an ‘Heirloom Development Tools’ m4 but in that case will have to
increase the pushback buffer size; I had success with ‘m4
-B100000’. If you use GNU m4 or OpenBSD m4 you should encounter no
difficulty.

(The biggest drawback of this ancient Heirloom m4 implementation is
not the need to set buffer sizes, but that it is ASCII-only. I should
quit supporting it in my packages, so I could more freely use UTF-8,
but am pathologically a worry-wart.)