vector-0.5: Efficient Arrays

Portability non-portable experimental Roman Leshchinskiy

Data.Vector.Primitive

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 s a Source

Mutable vectors of primitive types.

Constructors

 MVector !Int !Int !(MutableByteArray s)

Instances

 Prim a => MVector MVector a

class Prim a

Class of types supporting primitive array operations

Instances

 Prim Char Prim Double Prim Float Prim Int Prim Int8 Prim Int16 Prim Int32 Prim Int64 Prim Word Prim Word8 Prim Word16 Prim Word32 Prim Word64 Prim Addr

# 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

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

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

(++) :: 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

indexM :: (Prim a, Monad m) => Vector a -> Int -> m aSource

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

headM :: (Prim a, Monad m) => Vector a -> m aSource

lastM :: (Prim a, Monad m) => Vector a -> m aSource

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

Unsafe indexing without bounds checking

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

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

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

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

unsafeIndexM :: (Prim a, Monad m) => Vector a -> Int -> m aSource

Unsafe monadic indexing without bounds checks

unsafeHeadM :: (Prim a, Monad m) => Vector a -> m aSource

unsafeLastM :: (Prim a, Monad m) => Vector a -> m aSource

# Subvectors

Arguments

 :: Prim a => Int starting index -> Int length -> Vector a -> Vector a

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

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.

Arguments

 :: Prim a => 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 :: Prim a => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector aSource

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

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

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

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

unsafeUpd :: 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

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

Apply a function to every index/value pair

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.

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

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

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

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

Zip two vectors and their indices with the given function.

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

Zip three vectors and their indices with the given function.

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

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

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

# Filtering

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

Drop elements which do not satisfy the predicate

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

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

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.

partition :: Prim a => (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 :: Prim a => (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 :: Prim a => (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 :: Prim a => (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 :: (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.

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

Yield the indices of elements satisfying the predicate

elemIndex :: (Prim a, 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 :: (Prim a, Eq a) => a -> Vector a -> Vector IntSource

Yield the indices of all occurences of the given element

# 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

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

Right fold with a strict accumulator

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

Right fold on non-empty vectors with strict accumulator

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

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

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

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

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

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

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

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

# Specialised folds

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

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

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

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

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

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

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

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

minIndex :: (Prim a, Ord a) => Vector a -> IntSource

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

maxIndex :: (Prim a, Ord a) => Vector a -> IntSource

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

# 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

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

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

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

Prefix right-to-left scan

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

Prefix right-to-left scan with strict accumulator

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

Suffix right-to-left scan

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

Suffix right-to-left scan with strict accumulator

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

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

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

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

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

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

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

# Enumeration

enumFromN :: (Prim a, 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 :: (Prim a, 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 :: (Prim a, 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 :: (Prim a, 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 :: Prim a => Vector a -> [a]Source

Convert a vector to a list

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

Convert a list to a vector