vector-0.5: Efficient Arrays

Portabilitynon-portable
Stabilityexperimental
MaintainerRoman Leshchinskiy <rl@cse.unsw.edu.au>

Data.Vector

Contents

Description

Boxed vectors

Synopsis

Documentation

data Vector a Source

Instances

Vector Vector a 
Eq a => Eq (Vector a) 
Ord a => Ord (Vector a) 
Show a => Show (Vector a) 

data MVector s a Source

Mutable boxed vectors keyed on the monad they live in (IO or ST s).

Instances

Length information

Construction

empty :: Vector aSource

Empty vector

singleton :: a -> Vector aSource

Vector with exaclty one element

cons :: a -> Vector a -> Vector aSource

Prepend an element

snoc :: Vector a -> a -> Vector aSource

Append an element

replicate :: Int -> a -> Vector aSource

Vector of the given length with the given value in each position

generate :: Int -> (Int -> a) -> Vector aSource

Generate a vector of the given length by applying the function to each index

(++) :: Vector a -> Vector a -> Vector aSource

Concatenate two vectors

copy :: Vector a -> Vector aSource

Create a copy of a vector. Useful when dealing with slices.

Accessing individual elements

(!) :: Vector a -> Int -> aSource

Indexing

head :: Vector a -> aSource

First element

last :: Vector a -> aSource

Last element

indexM :: Monad m => Vector a -> Int -> m aSource

Monadic indexing which can be strict in the vector while remaining lazy in the element

headM :: Monad m => Vector a -> m aSource

lastM :: Monad m => Vector a -> m aSource

unsafeIndex :: Vector a -> Int -> aSource

Unsafe indexing without bounds checking

unsafeHead :: Vector a -> aSource

Yield the first element of a vector without checking if the vector is empty

unsafeLast :: Vector a -> aSource

Yield the last element of a vector without checking if the vector is empty

unsafeIndexM :: Monad m => Vector a -> Int -> m aSource

Unsafe monadic indexing without bounds checks

unsafeHeadM :: Monad m => Vector a -> m aSource

unsafeLastM :: Monad m => Vector a -> m aSource

Subvectors

sliceSource

Arguments

:: Int

starting index

-> Int

length

-> Vector a 
-> Vector a 

Yield a part of the vector without copying it. Safer version of basicUnsafeSlice.

init :: Vector a -> Vector aSource

Yield all but the last element without copying.

tail :: Vector a -> Vector aSource

All but the first element (without copying).

take :: Int -> Vector a -> Vector aSource

Yield the first n elements without copying.

drop :: Int -> Vector a -> Vector aSource

Yield all but the first n elements without copying.

unsafeSliceSource

Arguments

:: Int

starting index

-> Int

length

-> Vector a 
-> Vector a 

Unsafely yield a part of the vector without copying it and without performing bounds checks.

Permutations

accum :: (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector aSource

accumulate :: (a -> b -> a) -> Vector a -> Vector (Int, b) -> Vector aSource

accumulate_ :: (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector aSource

(//) :: Vector a -> [(Int, a)] -> Vector aSource

update :: Vector a -> Vector (Int, a) -> Vector aSource

unsafeAccum :: (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector aSource

unsafeAccumulate :: (a -> b -> a) -> Vector a -> Vector (Int, b) -> Vector aSource

unsafeAccumulate_ :: (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector aSource

unsafeUpd :: Vector a -> [(Int, a)] -> Vector aSource

Mapping

map :: (a -> b) -> Vector a -> Vector bSource

Map a function over a vector

imap :: (Int -> a -> b) -> Vector a -> Vector bSource

Apply a function to every index/value pair

concatMap :: (a -> Vector b) -> Vector a -> Vector bSource

Zipping and unzipping

zipWith :: (a -> b -> c) -> Vector a -> Vector b -> Vector cSource

Zip two vectors with the given function.

zipWith3 :: (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector dSource

Zip three vectors with the given function.

zipWith4 :: (a -> b -> c -> d -> e) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector eSource

zipWith5 :: (a -> b -> c -> d -> e -> f) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector fSource

zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector gSource

izipWith :: (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector cSource

Zip two vectors and their indices with the given function.

izipWith3 :: (Int -> a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector dSource

Zip three vectors and their indices with the given function.

izipWith4 :: (Int -> a -> b -> c -> d -> e) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector eSource

izipWith5 :: (Int -> a -> b -> c -> d -> e -> f) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector fSource

izipWith6 :: (Int -> a -> b -> c -> d -> e -> f -> g) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector gSource

zip :: Vector a -> Vector b -> Vector (a, b)Source

zip3 :: Vector a -> Vector b -> Vector c -> Vector (a, b, c)Source

zip4 :: Vector a -> Vector b -> Vector c -> Vector d -> Vector (a, b, c, d)Source

zip5 :: Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector (a, b, c, d, e)Source

zip6 :: Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector (a, b, c, d, e, f)Source

unzip :: Vector (a, b) -> (Vector a, Vector b)Source

unzip3 :: Vector (a, b, c) -> (Vector a, Vector b, Vector c)Source

unzip4 :: Vector (a, b, c, d) -> (Vector a, Vector b, Vector c, Vector d)Source

unzip5 :: Vector (a, b, c, d, e) -> (Vector a, Vector b, Vector c, Vector d, Vector e)Source

unzip6 :: Vector (a, b, c, d, e, f) -> (Vector a, Vector b, Vector c, Vector d, Vector e, Vector f)Source

Filtering

filter :: (a -> Bool) -> Vector a -> Vector aSource

Drop elements which do not satisfy the predicate

ifilter :: (Int -> a -> Bool) -> Vector a -> Vector aSource

Drop elements that do not satisfy the predicate (applied to values and their indices)

takeWhile :: (a -> Bool) -> Vector a -> Vector aSource

Yield the longest prefix of elements satisfying the predicate.

dropWhile :: (a -> Bool) -> Vector a -> Vector aSource

Drop the longest prefix of elements that satisfy the predicate.

partition :: (a -> Bool) -> Vector a -> (Vector a, Vector a)Source

Split the vector in two parts, the first one containing those elements that satisfy the predicate and the second one those that don't. The relative order of the elements is preserved at the cost of a (sometimes) reduced performance compared to unstablePartition.

unstablePartition :: (a -> Bool) -> Vector a -> (Vector a, Vector a)Source

Split the vector in two parts, the first one containing those elements that satisfy the predicate and the second one those that don't. The order of the elements is not preserved.

span :: (a -> Bool) -> Vector a -> (Vector a, Vector a)Source

Split the vector into the longest prefix of elements that satisfy the predicate and the rest.

break :: (a -> Bool) -> Vector a -> (Vector a, Vector a)Source

Split the vector into the longest prefix of elements that do not satisfy the predicate and the rest.

Searching

elem :: Eq a => a -> Vector a -> BoolSource

Check whether the vector contains an element

notElem :: Eq a => a -> Vector a -> BoolSource

Inverse of elem

find :: (a -> Bool) -> Vector a -> Maybe aSource

Yield Just the first element matching the predicate or Nothing if no such element exists.

findIndex :: (a -> Bool) -> Vector a -> Maybe IntSource

Yield Just the index of the first element matching the predicate or Nothing if no such element exists.

findIndices :: (a -> Bool) -> Vector a -> Vector IntSource

Yield the indices of elements satisfying the predicate

elemIndex :: Eq a => a -> Vector a -> Maybe IntSource

Yield Just the index of the first occurence of the given element or Nothing if the vector does not contain the element

elemIndices :: Eq a => a -> Vector a -> Vector IntSource

Yield the indices of all occurences of the given element

Folding

foldl :: (a -> b -> a) -> a -> Vector b -> aSource

Left fold

foldl1 :: (a -> a -> a) -> Vector a -> aSource

Lefgt fold on non-empty vectors

foldl' :: (a -> b -> a) -> a -> Vector b -> aSource

Left fold with strict accumulator

foldl1' :: (a -> a -> a) -> Vector a -> aSource

Left fold on non-empty vectors with strict accumulator

foldr :: (a -> b -> b) -> b -> Vector a -> bSource

Right fold

foldr1 :: (a -> a -> a) -> Vector a -> aSource

Right fold on non-empty vectors

foldr' :: (a -> b -> b) -> b -> Vector a -> bSource

Right fold with a strict accumulator

foldr1' :: (a -> a -> a) -> Vector a -> aSource

Right fold on non-empty vectors with strict accumulator

ifoldl :: (a -> Int -> b -> a) -> a -> Vector b -> aSource

Left fold (function applied to each element and its index)

ifoldl' :: (a -> Int -> b -> a) -> a -> Vector b -> aSource

Left fold with strict accumulator (function applied to each element and its index)

ifoldr :: (Int -> a -> b -> b) -> b -> Vector a -> bSource

Right fold (function applied to each element and its index)

ifoldr' :: (Int -> a -> b -> b) -> b -> Vector a -> bSource

Right fold with strict accumulator (function applied to each element and its index)

Specialised folds

all :: (a -> Bool) -> Vector a -> BoolSource

any :: (a -> Bool) -> Vector a -> BoolSource

sum :: Num a => Vector a -> aSource

product :: Num a => Vector a -> aSource

maximum :: Ord a => Vector a -> aSource

maximumBy :: (a -> a -> Ordering) -> Vector a -> aSource

minimum :: Ord a => Vector a -> aSource

minimumBy :: (a -> a -> Ordering) -> Vector a -> aSource

minIndexBy :: (a -> a -> Ordering) -> Vector a -> IntSource

maxIndexBy :: (a -> a -> Ordering) -> Vector a -> IntSource

Unfolding

unfoldr :: (b -> Maybe (a, b)) -> b -> Vector aSource

Scans

prescanl :: (a -> b -> a) -> a -> Vector b -> Vector aSource

Prefix scan

prescanl' :: (a -> b -> a) -> a -> Vector b -> Vector aSource

Prefix scan with strict accumulator

postscanl :: (a -> b -> a) -> a -> Vector b -> Vector aSource

Suffix scan

postscanl' :: (a -> b -> a) -> a -> Vector b -> Vector aSource

Suffix scan with strict accumulator

scanl :: (a -> b -> a) -> a -> Vector b -> Vector aSource

Haskell-style scan

scanl' :: (a -> b -> a) -> a -> Vector b -> Vector aSource

Haskell-style scan with strict accumulator

scanl1 :: (a -> a -> a) -> Vector a -> Vector aSource

Scan over a non-empty Vector

scanl1' :: (a -> a -> a) -> Vector a -> Vector aSource

Scan over a non-empty Vector with a strict accumulator

prescanr :: (a -> b -> b) -> b -> Vector a -> Vector bSource

Prefix right-to-left scan

prescanr' :: (a -> b -> b) -> b -> Vector a -> Vector bSource

Prefix right-to-left scan with strict accumulator

postscanr :: (a -> b -> b) -> b -> Vector a -> Vector bSource

Suffix right-to-left scan

postscanr' :: (a -> b -> b) -> b -> Vector a -> Vector bSource

Suffix right-to-left scan with strict accumulator

scanr :: (a -> b -> b) -> b -> Vector a -> Vector bSource

Haskell-style right-to-left scan

scanr' :: (a -> b -> b) -> b -> Vector a -> Vector bSource

Haskell-style right-to-left scan with strict accumulator

scanr1 :: (a -> a -> a) -> Vector a -> Vector aSource

Right-to-left scan over a non-empty vector

scanr1' :: (a -> a -> a) -> Vector a -> Vector aSource

Right-to-left scan over a non-empty vector with a strict accumulator

Enumeration

enumFromN :: Num a => a -> Int -> Vector aSource

Yield a vector of the given length containing the values x, x+1 etc. This operation is usually more efficient than enumFromTo.

enumFromStepN :: Num a => a -> a -> Int -> Vector aSource

Yield a vector of the given length containing the values x, x+y, x+y+y etc. This operations is usually more efficient than enumFromThenTo.

enumFromTo :: Enum a => a -> a -> Vector aSource

Enumerate values from x to y.

WARNING: This operation can be very inefficient. If at all possible, use enumFromN instead.

enumFromThenTo :: Enum a => a -> a -> a -> Vector aSource

Enumerate values from x to y with a specific step z.

WARNING: This operation can be very inefficient. If at all possible, use enumFromStepN instead.

Conversion to/from lists

toList :: Vector a -> [a]Source

Convert a vector to a list

fromList :: [a] -> Vector aSource

Convert a list to a vector