Sorts an array using the default ordering. Both Lexicographic and Ord are necessary because the algorithm falls back to insertion sort for sufficiently small arrays.
Modulevector-algorithms-0.9.1.0Haskell2010
Data.Vector.Algorithms.AmericanFlag
This module implements American flag sort: an in-place, unstable, bucket sort. Also in contrast to radix sort, the values are inspected in a big endian order, and buckets are sorted via recursive splitting. This, however, makes it sensible for sorting strings in lexicographic order (provided indexing is fast).
The algorithm works as follows: at each stage, the array is looped over, counting the number of elements for each bucket. Then, starting at the beginning of the array, elements are permuted in place to reside in the proper bucket, following chains until they reach back to the current base index. Finally, each bucket is sorted recursively. This lends itself well to the aforementioned variable-length strings, and so the algorithm takes a stopping predicate, which is given a representative of the stripe, rather than running for a set number of iterations.
- 1 class
- 5 values
- Packagevector-algorithms-0.9.1.0
- Exports6
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceAmericanFlag.hs
A variant on sort that returns a vector of unique elements.
sortBy A fully parameterized version of the sorting algorithm. Again, this function takes both radix information and a comparison, because the algorithms falls back to insertion sort for small arrays.
sortUniqBy :: (PrimMonad m, MVector v e)=> Comparison ea comparison for the insertion sort flalback
-> (e -> Int -> Bool)determines whether a stripe is complete
-> Intthe number of buckets necessary
-> (Int -> e -> Int)the big-endian radix function
-> v (PrimState m) ethe array to be sorted
-> m (v (PrimState m) e)
A variant on sortBy which returns a vector of unique elements.
Given a representative of a stripe and an index number, this function determines whether to stop sorting.
The methods of this class specify the information necessary to sort arrays using the default ordering. The name Lexicographic is meant to convey that index should return results in a similar way to indexing into a string.
Methods
extent :: e -> IntComputes the length of a representative of a stripe. It should take
npasses to sort values of extentn. The extent may not be uniform across all values of the type.size :: Proxy e -> IntThe size of the bucket array necessary for sorting es
index :: Int -> e -> IntDetermines which bucket a given element should inhabit for a particular iteration.
Instances13Lexicographic, …
Lexicographic ByteStringDefined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic Int16Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic Int32Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic Int64Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic Int8Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic Word16Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic Word32Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic Word64Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic Word8Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic IntDefined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlagLexicographic WordDefined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlag(Lexicographic a, Lexicographic b) => Lexicographic (Either a b)Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlag(Lexicographic a, Lexicographic b) => Lexicographic (a, b)Defined in vector-algorithms-0.9.1.0 · Data.Vector.Algorithms.AmericanFlag