haccepted-0.1.0.0: Data structures and algorithms
Safe HaskellNone
LanguageHaskell2010

Sort

Description

Sorting

Data.List.sort is rather inefficient when we don't care about laziness and just want to fully sort a list. An in-place sort can have much better performance. Benchmarks show that for a list of Ints, sort and sortU are 4x and 8x faster than Data.List.sort.

sort, sortBy, sortU, sortUBy use merge sort. countingSortUA uses counting sort. Both are stable sorts.

Sources:

Synopsis

Documentation

sort :: Ord e => [e] -> [e] Source #

Sorts a list. O(n log n).

sortBy :: (e -> e -> Ordering) -> [e] -> [e] Source #

Sorts a list with a comparison function. O(n log n).

sortU :: (Ord e, forall s. MArray (STUArray s) e (ST s), IArray UArray e) => [e] -> [e] Source #

Sorts a list for an element type that can be put in unboxed arrays. Faster than sort. O(n log n).

sortUBy :: (forall s. MArray (STUArray s) e (ST s), IArray UArray e) => (e -> e -> Ordering) -> [e] -> [e] Source #

Sorts a list for an element type that can be put in unboxed arrays with a comparison function. Faster than sortBy. O(n log n).

sortUABy :: (forall s. MArray (STUArray s) e (ST s), IArray UArray e) => (e -> e -> Ordering) -> UArray Int e -> UArray Int e Source #

Sorts an unboxed array with a comparison function. O(n log n).

countingSortUA :: (IArray UArray e, forall s. MArray (STUArray s) e (ST s)) => Int -> (e -> Int) -> UArray Int e -> UArray Int e Source #

Sorts an unboxed array using counting sort. f should be a function that maps every element to an Int in [0..b-1]. O(n + b).