vector-0.4.2: Efficient Arrays

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

Data.Vector.Primitive

Contents

Description

Unboxed vectors of primitive types.

Synopsis

Documentation

data Vector a Source

Unboxed vectors of primitive types

Instances

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

data MVector m a Source

Mutable unboxed vectors. They live in the ST monad.

Constructors

MVector !Int !Int !(MutableByteArray m) 

Instances

Prim a => MVectorPure (MVector m) a 
(Prim a, PrimMonad m) => MVector (MVector m) m a 

class Prim a

Class of types supporting primitive array operations

Length information

null :: Prim a => Vector a -> BoolSource

Construction

empty :: Prim a => Vector aSource

Empty vector

singleton :: Prim a => a -> Vector aSource

Vector with exaclty one element

cons :: Prim a => a -> Vector a -> Vector aSource

Prepend an element

snoc :: Prim a => Vector a -> a -> Vector aSource

Append an element

replicate :: Prim a => Int -> a -> Vector aSource

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

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

Concatenate two vectors

copy :: Prim a => Vector a -> Vector aSource

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

Accessing individual elements

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

Indexing

head :: Prim a => Vector a -> aSource

First element

last :: Prim a => Vector a -> aSource

Last element

Subvectors

sliceSource

Arguments

:: Prim a 
=> Vector a 
-> Int

starting index

-> Int

length

-> Vector a 

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

init :: Prim a => Vector a -> Vector aSource

Yield all but the last element without copying.

tail :: Prim a => Vector a -> Vector aSource

All but the first element (without copying).

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

Yield the first n elements without copying.

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

Yield all but the first n elements without copying.

Permutations

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

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

Mapping

map :: (Prim a, Prim b) => (a -> b) -> Vector a -> Vector bSource

Map a function over a vector

concatMap :: (Prim a, Prim b) => (a -> Vector b) -> Vector a -> Vector bSource

Zipping and unzipping

zipWith :: (Prim a, Prim b, Prim c) => (a -> b -> c) -> Vector a -> Vector b -> Vector cSource

Zip two vectors with the given function.

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

Zip three vectors with the given function.

Filtering

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

Drop elements which do not satisfy the predicate

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

Yield the longest prefix of elements satisfying the predicate.

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

Drop the longest prefix of elements that satisfy the predicate.

Searching

elem :: (Prim a, Eq a) => a -> Vector a -> BoolSource

Check whether the vector contains an element

notElem :: (Prim a, Eq a) => a -> Vector a -> BoolSource

Inverse of elem

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

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

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

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

Folding

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

Left fold

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

Lefgt fold on non-empty vectors

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

Left fold with strict accumulator

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

Left fold on non-empty vectors with strict accumulator

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

Right fold

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

Right fold on non-empty vectors

Specialised folds

sum :: (Prim a, Num a) => Vector a -> aSource

product :: (Prim a, Num a) => Vector a -> aSource

maximum :: (Prim a, Ord a) => Vector a -> aSource

minimum :: (Prim a, Ord a) => Vector a -> aSource

Unfolding

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

Scans

prescanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector aSource

Prefix scan

prescanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector aSource

Prefix scan with strict accumulator

postscanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector aSource

Suffix scan

postscanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector aSource

Suffix scan with strict accumulator

scanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector aSource

Haskell-style scan

scanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector aSource

Haskell-style scan with strict accumulator

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

Scan over a non-empty Vector

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

Scan over a non-empty Vector with a strict accumulator

Enumeration

enumFromTo :: (Prim a, Enum a) => a -> a -> Vector aSource

enumFromThenTo :: (Prim a, Enum a) => a -> a -> a -> Vector aSource

Conversion to/from lists

toList :: Prim a => Vector a -> [a]Source

Convert a vector to a list

fromList :: Prim a => [a] -> Vector aSource

Convert a list to a vector