quickselect-0.1.0.0

Copyright(c) Donnacha Oisín Kidney 2018
LicenseMIT
Maintainermail@doisinkidney.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Data.Select.Unboxed.Intro

Description

This module provides an implementation of introselect on unboxed vectors. It begins as quickselect, but if it discovers it's in a pathological case, it switches to a median-of-medians implementation. This guarantees \(\mathcal{O}(n)\) worst-case time.

Synopsis

Documentation

selectBy :: Unbox a => (a -> a -> Bool) -> Int -> Vector a -> a Source #

\(\mathcal{O}(n)\). Find the nth item, ordered by the supplied relation.

i >= 0 && i < length xs ==> sort xs !! i === selectBy (<=) i (Vector.fromList (xs :: [Int]))

select :: (Unbox a, Ord a) => Int -> Vector a -> a Source #

\(\mathcal{O}(n)\). Find the nth smallest item in the vector.

>>> select 4 (Vector.fromList "this is an example")
'a'
>>> select 3 (Vector.fromList [0,1,4,2,3,5,6]) :: Int
3