vector-0.4.2: Efficient Arrays

Portability non-portable experimental Roman Leshchinskiy

Data.Vector.Generic.Mutable

Description

Generic interface to mutable vectors

Synopsis

# Documentation

class MVectorPure v a whereSource

Basic pure functions on mutable vectors

Methods

length :: v a -> IntSource

Length of the mutable vector

Arguments

 :: v a -> Int starting index -> Int length of the slice -> v a

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

overlaps :: v a -> v a -> BoolSource

Instances

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

class (Monad m, MVectorPure v a) => MVector v m a whereSource

Class of mutable vectors. The type `m` is the monad in which the mutable vector can be transformed and `a` is the type of elements.

Methods

unsafeNew :: Int -> m (v a)Source

Create a mutable vector of the given length. Length is not checked!

unsafeNewWith :: Int -> a -> m (v a)Source

Create a mutable vector of the given length and fill it with an initial value. Length is not checked!

unsafeRead :: v a -> Int -> m aSource

Yield the element at the given position. Index is not checked!

unsafeWrite :: v a -> Int -> a -> m ()Source

Replace the element at the given position. Index is not checked!

clear :: v a -> m ()Source

Clear all references to external objects

set :: v a -> a -> m ()Source

Write the value at each position.

Arguments

 :: v a target -> v a source -> m ()

Copy a vector. The two vectors may not overlap. This is not checked!

unsafeGrow :: v a -> Int -> m (v a)Source

Grow a vector by the given number of elements. The length is not checked!

Instances

 Storable a => MVector MVector IO a (Prim a, PrimMonad m) => MVector (MVector m) m a PrimMonad m => MVector (MVector m) m a

slice :: MVectorPure v a => v a -> Int -> Int -> v aSource

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

new :: MVector v m a => Int -> m (v a)Source

Create a mutable vector of the given length. Safer version of `unsafeNew`.

newWith :: MVector v m a => Int -> a -> m (v a)Source

Create a mutable vector of the given length and fill it with an initial value. Safer version of `unsafeNewWith`.

read :: MVector v m a => v a -> Int -> m aSource

Yield the element at the given position. Safer version of `unsafeRead`.

write :: MVector v m a => v a -> Int -> a -> m ()Source

Replace the element at the given position. Safer version of `unsafeWrite`.

copy :: MVector v m a => v a -> v a -> m ()Source

Copy a vector. The two vectors may not overlap. Safer version of `unsafeCopy`.

grow :: MVector v m a => v a -> Int -> m (v a)Source

Grow a vector by the given number of elements. Safer version of `unsafeGrow`.

unstream :: MVector v m a => Stream a -> m (v a)Source

Create a new mutable vector and fill it with elements from the `Stream`. The vector will grow logarithmically if the `Size` hint of the `Stream` is inexact.

transform :: MVector v m a => (MStream m a -> MStream m a) -> v a -> m (v a)Source

accum :: MVector v m a => (a -> b -> a) -> v a -> Stream (Int, b) -> m ()Source

update :: MVector v m a => v a -> Stream (Int, a) -> m ()Source

reverse :: MVector v m a => v a -> m ()Source