uvector-algorithms-0.2: Efficient algorithms for uvector unboxed arrays

PortabilityNon-portable (rank-2 types)
MaintainerDan Doel <dan.doel@gmail.com>



The purpose of this module is to supply various combinators for commonly used idioms for the algorithms in this package. Examples at the time of this writing include running an algorithm keyed on some function of the elements (but only computing said function once per element), and safely applying the algorithms on mutable arrays to immutable arrays.



apply :: UA e => (forall s. MUArr e s -> ST s ()) -> UArr e -> UArr eSource

Safely applies a mutable array algorithm to an immutable array.

usingKeys :: (UA e, UA k, Ord k) => (forall e'. UA e' => Comparison e' -> MUArr e' s -> ST s ()) -> (e -> k) -> MUArr e s -> ST s ()Source

Uses a function to compute a key for each element which the algorithm should use in lieu of the actual element. For instance:

 usingKeys sortBy f arr

should produce the same results as:

 sortBy (comparing f) arr

the difference being that usingKeys computes each key only once which can be more efficient for expensive key functions.

usingIxKeys :: (UA e, UA k, Ord k) => (forall e'. UA e' => Comparison e' -> MUArr e' s -> ST s ()) -> (Int -> e -> k) -> MUArr e s -> ST s ()Source

As usingKeys, only the key function has access to the array index at which each element is stored.