primitive-sort-0.1.2.3: Sort primitive arrays
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Primitive.Sort

Description

Sort primitive arrays with a stable sorting algorithm. All functions in this module are marked as INLINABLE, so they will specialize when used in a monomorphic setting.

Synopsis

Immutable

sort :: (Prim a, Ord a) => PrimArray a -> PrimArray a Source #

Sort an immutable array. Duplicate elements are preserved.

sortUnique :: (Prim a, Ord a) => PrimArray a -> PrimArray a Source #

Sort an immutable array. Only a single copy of each duplicated element is preserved.

sortTagged Source #

Arguments

:: forall k v karr varr. (Contiguous karr, Element karr k, Ord k, Contiguous varr, Element varr v) 
=> karr k

keys

-> varr v

values

-> (karr k, varr v) 

Sort a tagged immutable array. Each element from the keys array is paired up with an element from the values array at the matching index. The sort permutes the values array so that a value end up in the same position as its corresponding key. The two argument array should be of the same length, but if one is shorter than the other, the longer one will be truncated so that the lengths match.

Since the sort is stable, the values corresponding to a key that appears multiple times have their original order preserved.

sortUniqueTagged Source #

Arguments

:: forall k v karr varr. (ContiguousU karr, Element karr k, Ord k, ContiguousU varr, Element varr v) 
=> karr k

keys

-> varr v

values

-> (karr k, varr v) 

Sort a tagged immutable array. Only a single copy of each duplicate key is preserved, along with the last value from values that corresponded to it. The two argument arrays should be of the same length, but if one is shorter than the other, the longer one will be truncated so that the lengths match.

Mutable

sortMutable :: (Prim a, Ord a) => MutablePrimArray s a -> ST s (MutablePrimArray s a) Source #

Sort the mutable array. This operation preserves duplicate elements. The argument may either be modified in-place, or another array may be allocated and returned. The argument may not be reused after being passed to this function.

sortUniqueMutable :: forall s a. (Prim a, Ord a) => MutablePrimArray s a -> ST s (MutablePrimArray s a) Source #

Sort an immutable array. Only a single copy of each duplicated element is preserved. This operation may run in-place, or it may need to allocate a new array, so the argument may not be reused after this function is applied to it.

sortTaggedMutable :: (ContiguousU karr, Element karr k, Ord k, ContiguousU varr, Element varr v) => Mutable karr s k -> Mutable varr s v -> ST s (Mutable karr s k, Mutable varr s v) Source #

Sort an array of a key type k, rearranging the values of type v according to the element they correspond to in the key array. The argument arrays may not be reused after they are passed to the function.

sortUniqueTaggedMutable Source #

Arguments

:: (ContiguousU karr, Element karr k, Ord k, ContiguousU varr, Element varr v) 
=> Mutable karr s k

keys

-> Mutable varr s v

values

-> ST s (Mutable karr s k, Mutable varr s v)