HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulevector-algorithms-0.9.1.0Haskell2010

Data.Vector.Algorithms.Radix

This module provides a radix sort for a subclass of unboxed arrays. The radix class gives information on * the number of passes needed for the data type

  • the size of the auxiliary arrays

  • how to compute the pass-k radix of a value

Radix sort is not a comparison sort, so it is able to achieve O(n) run time, though it also uses O(n) auxiliary space. In addition, there is a constant space overhead of 2*size*sizeOf(Int) for the sort, so it is not advisable to use this sort for large numbers of very small arrays.

A standard example (upon which one could base their own Radix instance) is Word32:

  • We choose to sort on r = 8 bits at a time

  • A Word32 has b = 32 bits total

Thus, b/r = 4 passes are required, 2^r = 256 elements are needed in an auxiliary array, and the radix function is:

radix k e = (e `shiftR` (k*8)) .&. 255
  • 1 class
  • 2 values
valuesortBy
  1. :: (PrimMonad m, MVector v e)
  2. => Int

    the number of passes

  3. -> Int

    the size of auxiliary arrays

  4. -> (Int -> e -> Int)

    the radix function

  5. -> v (PrimState m) e

    the array to be sorted

  6. -> m ()
#

Radix sorts an array using custom radix information requires the number of passes to fully sort the array, the size of of auxiliary arrays necessary (should be one greater than the maximum value returned by the radix function), and a radix function, which takes the pass and an element, and returns the relevant radix.

classclass Radix e where
#

Methods

  • passes :: e -> Int

    The number of passes necessary to sort an array of es

  • size :: e -> Int

    The size of an auxiliary array

  • radix :: Int -> e -> Int

    The radix function parameterized by the current pass

Instances11Radix, …
  • Radix Int16Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • Radix Int32Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • Radix Int64Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • Radix Int8Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • Radix Word16Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • Radix Word32Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • Radix Word64Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • Radix Word8Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • Radix IntDefined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • Radix WordDefined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix
  • (Radix i, Radix j) => Radix (i, j)Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.Radix