Data.Vector.Algorithms.Radix

vector-algorithms-0.9.0.3: Efficient algorithms for vector arrays

Copyright | (c) 2008-2011 Dan Doel
Maintainer | Dan Doel <dan.doel@gmail.com>
Stability | Experimental
Portability | Non-portable (scoped type variables, bang patterns)
Safe Haskell | None
Language | Haskell2010

Data.Vector.Algorithms.Radix

Description

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

Synopsis

- sort :: forall e m v. (PrimMonad m, MVector v e, Radix e) => v (PrimState m) e -> m ()
- sortBy :: (PrimMonad m, MVector v e) => Int -> Int -> (Int -> e -> Int) -> v (PrimState m) e -> m ()
- class Radix e where
  - passes :: e -> Int
  - size :: e -> Int
  - radix :: Int -> e -> Int

# Documentation

sort :: forall e m v. (PrimMonad m, MVector v e, Radix e) => v (PrimState m) e -> m () #

Sorts an array based on the Radix instance.

sortBy #

Arguments

:: (PrimMonad m, MVector v e) |
=> Int | the number of passes
-> Int | the size of auxiliary arrays
-> (Int -> e -> Int) | the radix function
-> v (PrimState m) e | the array to be sorted
-> 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.

class 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

#### Instances

Instances details

Radix Int16 # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Int16 -> Int # size :: Int16 -> Int # radix :: Int -> Int16 -> Int #
Radix Int32 # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Int32 -> Int # size :: Int32 -> Int # radix :: Int -> Int32 -> Int #
Radix Int64 # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Int64 -> Int # size :: Int64 -> Int # radix :: Int -> Int64 -> Int #
Radix Int8 # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Int8 -> Int # size :: Int8 -> Int # radix :: Int -> Int8 -> Int #
Radix Word16 # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Word16 -> Int # size :: Word16 -> Int # radix :: Int -> Word16 -> Int #
Radix Word32 # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Word32 -> Int # size :: Word32 -> Int # radix :: Int -> Word32 -> Int #
Radix Word64 # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Word64 -> Int # size :: Word64 -> Int # radix :: Int -> Word64 -> Int #
Radix Word8 # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Word8 -> Int # size :: Word8 -> Int # radix :: Int -> Word8 -> Int #
Radix Int # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Int -> Int # size :: Int -> Int # radix :: Int -> Int -> Int #
Radix Word # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: Word -> Int # size :: Word -> Int # radix :: Int -> Word -> Int #
(Radix i, Radix j) => Radix (i, j) # |
Instance details Defined in Data.Vector.Algorithms.Radix Methods passes :: (i, j) -> Int # size :: (i, j) -> Int # radix :: Int -> (i, j) -> Int #