The Perl Advent Calendar needs more articles for 2022. Submit your idea today!


Sort::Key::Radix - Radix sort implementation in XS


  use Sort::Key::Radix qw(ukeysort);
  my @sorted = ukeysort { $_->age } @people;


This module reimplements some of the funcions in the Sort::Key module using a Radix sort as the sorting algorithm.

For some kinds of data (for instance large data sets of small integers, postal codes, logins, serial numbers, dates, etc.) it can be faster than the Merge sort algorithm used internally by Perl and by Sort::Key.


The following functions are equivalent to those from Sort::Key that have the same name:

  isort, usort, nsort, risort, rusort, rnsort, isort_inplace,
  usort_inplace, nsort_inplace, risort_inplace, rusort_inplace,
  rnsort_inplace, ikeysort, ukeysort, nkeysort, rikeysort, rukeysort,
  rnkeysort, ikeysort_inplace, ukeysort_inplace, nkeysort_inplace,
  rikeysort_inplace, rukeysort_inplace, rnkeysort_inplace

And the following are also provided:

ssort, rssort, skeysort, ssort_inplace, etc.

First, these functions extend the keys to match the length of the largest one, appending "\000" chars to their right.

Then they perform an alphabetic radix sort interpreting the keys as byte strings (and that means that the unicode flag is ignored).

fsort, rfsort fkeysort, fsort_inplace, etc.

Before sorting the elements, these funcions convert the keys to single floating point values.

They are only available on computers where the size of the C float datatype is 32 bits.


Sort::Key and the Radix Sort algorithm description on the Wikipedia


This is an early release of the module, expect bugs on it, and if you find any, please, send me an email or use the CPAN bug tracking system at to report it!


Copyright (C) 2007, 2012 by Salvador Fandiño (

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.