vector-0.3: Efficient Arrays

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

Data.Vector.IVector

Contents

Description

Generic interface to pure vectors

Synopsis

Immutable vectors

class IVector v a whereSource

Class of immutable vectors.

Methods

vnew :: (forall mv m. MVector mv m a => m (mv a)) -> v aSource

Construct a pure vector from a monadic initialiser (not fusible!)

vlength :: v a -> IntSource

Length of the vector (not fusible!)

unsafeSlice :: v a -> Int -> Int -> v aSource

Yield a part of the vector without copying it. No range checks!

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

Instances

Length information

length :: IVector v a => v a -> IntSource

null :: IVector v a => v a -> BoolSource

Construction

empty :: IVector v a => v aSource

Empty vector

singleton :: IVector v a => a -> v aSource

Vector with exaclty one element

cons :: IVector v a => a -> v a -> v aSource

Prepend an element

snoc :: IVector v a => v a -> a -> v aSource

Append an element

replicate :: IVector v a => Int -> a -> v aSource

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

(++) :: IVector v a => v a -> v a -> v aSource

Concatenate two vectors

copy :: IVector v a => v a -> v aSource

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

Accessing individual elements

(!) :: IVector v a => v a -> Int -> aSource

Indexing

head :: IVector v a => v a -> aSource

First element

last :: IVector v a => v a -> aSource

Last element

indexM :: (IVector v a, Monad m) => v a -> Int -> m aSource

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

headM :: (IVector v a, Monad m) => v a -> m aSource

lastM :: (IVector v a, Monad m) => v a -> m aSource

Subvectors

sliceSource

Arguments

:: IVector v a 
=> v a 
-> Int

starting index

-> Int

length

-> v a 

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

init :: IVector v a => v a -> v aSource

Yield all but the last element without copying.

tail :: IVector v a => v a -> v aSource

All but the first element (without copying).

take :: IVector v a => Int -> v a -> v aSource

Yield the first n elements without copying.

drop :: IVector v a => Int -> v a -> v aSource

Yield all but the first n elements without copying.

Permutations

accum :: IVector v a => (a -> b -> a) -> v a -> [(Int, b)] -> v aSource

(//) :: IVector v a => v a -> [(Int, a)] -> v aSource

update :: (IVector v a, IVector v (Int, a)) => v a -> v (Int, a) -> v aSource

backpermute :: (IVector v a, IVector v Int) => v a -> v Int -> v aSource

reverse :: IVector v a => v a -> v aSource

Mapping

map :: (IVector v a, IVector v b) => (a -> b) -> v a -> v bSource

Map a function over a vector

concatMap :: (IVector v a, IVector v b) => (a -> v b) -> v a -> v bSource

Zipping and unzipping

zipWith :: (IVector v a, IVector v b, IVector v c) => (a -> b -> c) -> v a -> v b -> v cSource

Zip two vectors with the given function.

zipWith3 :: (IVector v a, IVector v b, IVector v c, IVector v d) => (a -> b -> c -> d) -> v a -> v b -> v c -> v dSource

Zip three vectors with the given function.

zip :: (IVector v a, IVector v b, IVector v (a, b)) => v a -> v b -> v (a, b)Source

zip3 :: (IVector v a, IVector v b, IVector v c, IVector v (a, b, c)) => v a -> v b -> v c -> v (a, b, c)Source

unzip :: (IVector v a, IVector v b, IVector v (a, b)) => v (a, b) -> (v a, v b)Source

unzip3 :: (IVector v a, IVector v b, IVector v c, IVector v (a, b, c)) => v (a, b, c) -> (v a, v b, v c)Source

Comparisons

eq :: (IVector v a, Eq a) => v a -> v a -> BoolSource

cmp :: (IVector v a, Ord a) => v a -> v a -> OrderingSource

Filtering

filter :: IVector v a => (a -> Bool) -> v a -> v aSource

Drop elements which do not satisfy the predicate

takeWhile :: IVector v a => (a -> Bool) -> v a -> v aSource

Yield the longest prefix of elements satisfying the predicate.

dropWhile :: IVector v a => (a -> Bool) -> v a -> v aSource

Drop the longest prefix of elements that satisfy the predicate.

Searching

elem :: (IVector v a, Eq a) => a -> v a -> BoolSource

Check whether the vector contains an element

notElem :: (IVector v a, Eq a) => a -> v a -> BoolSource

Inverse of elem

find :: IVector v a => (a -> Bool) -> v a -> Maybe aSource

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

findIndex :: IVector v a => (a -> Bool) -> v a -> Maybe IntSource

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

Folding

foldl :: IVector v b => (a -> b -> a) -> a -> v b -> aSource

Left fold

foldl1 :: IVector v a => (a -> a -> a) -> v a -> aSource

Lefgt fold on non-empty vectors

foldl' :: IVector v b => (a -> b -> a) -> a -> v b -> aSource

Left fold with strict accumulator

foldl1' :: IVector v a => (a -> a -> a) -> v a -> aSource

Left fold on non-empty vectors with strict accumulator

foldr :: IVector v a => (a -> b -> b) -> b -> v a -> bSource

Right fold

foldr1 :: IVector v a => (a -> a -> a) -> v a -> aSource

Right fold on non-empty vectors

Specialised folds

sum :: (IVector v a, Num a) => v a -> aSource

product :: (IVector v a, Num a) => v a -> aSource

maximum :: (IVector v a, Ord a) => v a -> aSource

minimum :: (IVector v a, Ord a) => v a -> aSource

Unfolding

unfoldr :: IVector v a => (b -> Maybe (a, b)) -> b -> v aSource

Scans

prescanl :: (IVector v a, IVector v b) => (a -> b -> a) -> a -> v b -> v aSource

Prefix scan

prescanl' :: (IVector v a, IVector v b) => (a -> b -> a) -> a -> v b -> v aSource

Prefix scan with strict accumulator

Enumeration

enumFromTo :: (IVector v a, Enum a) => a -> a -> v aSource

enumFromThenTo :: (IVector v a, Enum a) => a -> a -> a -> v aSource

Conversion to/from lists

toList :: IVector v a => v a -> [a]Source

Convert a vector to a list

fromList :: IVector v a => [a] -> v aSource

Convert a list to a vector

Conversion to/from Streams

stream :: IVector v a => v a -> Stream aSource

Convert a vector to a Stream

unstream :: IVector v a => Stream a -> v aSource

Create a vector from a Stream

MVector-based initialisation

new :: IVector v a => New a -> v aSource

Construct a pure vector from a monadic initialiser

Unsafe functions

Utility functions