vector-0.4.2: Efficient Arrays

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

Data.Vector.Storable

Contents

Description

Storable-based vectors.

Synopsis

Documentation

data Vector a Source

Storable-based vectors

Instances

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

data MVector a Source

Mutable Storable-based vectors in the IO monad.

Constructors

MVector !Int !Int !(ForeignPtr a) 

class Storable a

The member functions of this class facilitate writing values of primitive types to raw memory (which may have been allocated with the above mentioned routines) and reading values from blocks of raw memory. The class, furthermore, includes support for computing the storage requirements and alignment restrictions of storable types.

Memory addresses are represented as values of type Ptr a, for some a which is an instance of class Storable. The type argument to Ptr helps provide some valuable type safety in FFI code (you can't mix pointers of different types without an explicit cast), while helping the Haskell type system figure out which marshalling method is needed for a given pointer.

All marshalling between Haskell and a foreign language ultimately boils down to translating Haskell data structures into the binary representation of a corresponding data structure of the foreign language and vice versa. To code this marshalling in Haskell, it is necessary to manipulate primitive data types stored in unstructured memory blocks. The class Storable facilitates this manipulation on all types for which it is instantiated, which are the standard basic types of Haskell, the fixed size Int types (Int8, Int16, Int32, Int64), the fixed size Word types (Word8, Word16, Word32, Word64), StablePtr, all types from Foreign.C.Types, as well as Ptr.

Minimal complete definition: sizeOf, alignment, one of peek, peekElemOff and peekByteOff, and one of poke, pokeElemOff and pokeByteOff.

Length information

Construction

empty :: Storable a => Vector aSource

Empty vector

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

Vector with exaclty one element

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

Prepend an element

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

Append an element

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

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

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

Concatenate two vectors

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

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

Accessing individual elements

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

Indexing

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

First element

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

Last element

Subvectors

sliceSource

Arguments

:: Storable a 
=> Vector a 
-> Int

starting index

-> Int

length

-> Vector a 

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

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

Yield all but the last element without copying.

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

All but the first element (without copying).

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

Yield the first n elements without copying.

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

Yield all but the first n elements without copying.

Permutations

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

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

Mapping

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

Map a function over a vector

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

Zipping and unzipping

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

Zip two vectors with the given function.

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

Zip three vectors with the given function.

Filtering

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

Drop elements which do not satisfy the predicate

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

Yield the longest prefix of elements satisfying the predicate.

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

Drop the longest prefix of elements that satisfy the predicate.

Searching

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

Check whether the vector contains an element

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

Inverse of elem

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

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

findIndex :: Storable 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 :: Storable b => (a -> b -> a) -> a -> Vector b -> aSource

Left fold

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

Lefgt fold on non-empty vectors

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

Left fold with strict accumulator

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

Left fold on non-empty vectors with strict accumulator

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

Right fold

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

Right fold on non-empty vectors

Specialised folds

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

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

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

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

Unfolding

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

Scans

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

Prefix scan

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

Prefix scan with strict accumulator

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

Suffix scan

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

Suffix scan with strict accumulator

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

Haskell-style scan

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

Haskell-style scan with strict accumulator

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

Scan over a non-empty Vector

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

Scan over a non-empty Vector with a strict accumulator

Enumeration

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

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

Conversion to/from lists

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

Convert a vector to a list

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

Convert a list to a vector