hybrid-vectors-0.1: Hybrid vectors e.g. Mixed Boxed/Unboxed vectors

Safe HaskellNone

Data.Vector.Mixed.Mutable

Contents

Synopsis

Documentation

data MVector Source

A MVector s a is mutable vector that could have any vector type underneath

Accessors

Length information

length :: MVector u a => u s a -> IntSource

Length of the mutable vector.

null :: MVector u a => u s a -> BoolSource

Check whether the vector is empty

Extracting subvectors

slice :: Mixed u v a => Int -> Int -> u s a -> MVector s aSource

Yield a part of the mutable vector without copying it.

init :: Mixed u v a => u s a -> MVector s aSource

tail :: Mixed u v a => u s a -> MVector s aSource

take :: Mixed u v a => Int -> u s a -> MVector s aSource

drop :: Mixed u v a => Int -> u s a -> MVector s aSource

splitAt :: Mixed u v a => Int -> u s a -> (MVector s a, MVector s a)Source

unsafeSliceSource

Arguments

:: Mixed u v a 
=> Int

starting index

-> Int

length of the slice

-> u s a 
-> MVector s a 

Yield a part of the mutable vector without copying it. No bounds checks are performed.

unsafeInit :: Mixed u v a => u s a -> MVector s aSource

unsafeTail :: Mixed u v a => u s a -> MVector s aSource

unsafeTake :: Mixed u v a => Int -> u s a -> MVector s aSource

unsafeDrop :: Mixed u v a => Int -> u s a -> MVector s aSource

Overlapping

overlaps :: (Mixed u v a, Mixed u' v' a) => u s a -> u' s a -> BoolSource

Construction

replicateM :: PrimMonad m => Int -> m a -> m (MVector (PrimState m) a)Source

Create a mutable vector of the given length (0 if the length is negative) and fill it with values produced by repeatedly executing the monadic action.

move :: (PrimMonad m, Mixed u v a, Mixed u' v' a) => u (PrimState m) a -> u' (PrimState m) a -> m ()Source

Move the contents of a vector. The two vectors must have the same length.

If the vectors do not overlap, then this is equivalent to copy. Otherwise, the copying is performed as if the source vector were copied to a temporary vector and then the temporary vector was copied to the target vector.

unsafeMoveSource

Arguments

:: (PrimMonad m, Mixed u v a, Mixed u' v' a) 
=> u (PrimState m) a

target

-> u' (PrimState m) a

source

-> m () 

Move the contents of a vector. The two vectors must have the same length, but this is not checked.

If the vectors do not overlap, then this is equivalent to unsafeCopy. Otherwise, the copying is performed as if the source vector were copied to a temporary vector and then the temporary vector was copied to the target vector.

Initialisation

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

Create a mutable vector of the given length.

unsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) a)Source

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

replicate :: PrimMonad m => Int -> a -> m (MVector (PrimState m) a)Source

Create a mutable vector of the given length (0 if the length is negative) and fill it with an initial value.

clone :: (PrimMonad m, Mixed u v a) => u (PrimState m) a -> m (MVector (PrimState m) a)Source

Create a copy of a mutable vector.

Growing

grow :: (PrimMonad m, Mixed u v a) => u (PrimState m) a -> Int -> m (MVector (PrimState m) a)Source

Grow a vector by the given number of elements. The number must be positive.

unsafeGrow :: (PrimMonad m, Mixed u v a) => u (PrimState m) a -> Int -> m (MVector (PrimState m) a)Source

Grow a vector by the given number of elements. The number must be positive but this is not checked.

Restricting memory usage

clear :: (PrimMonad m, MVector u a) => u (PrimState m) a -> m ()Source

Reset all elements of the vector to some undefined value, clearing all references to external objects. This is usually a noop for unboxed vectors.

Accessing individual elements

read :: (PrimMonad m, MVector u a) => u (PrimState m) a -> Int -> m aSource

Yield the element at the given position.

write :: (PrimMonad m, MVector u a) => u (PrimState m) a -> Int -> a -> m ()Source

Replace the element at the given position.

swap :: (PrimMonad m, MVector u a) => u (PrimState m) a -> Int -> Int -> m ()Source

Swap the elements at the given positions.

unsafeRead :: (PrimMonad m, MVector u a) => u (PrimState m) a -> Int -> m aSource

Yield the element at the given position. No bounds checks are performed.

unsafeWrite :: (PrimMonad m, MVector u a) => u (PrimState m) a -> Int -> a -> m ()Source

Replace the element at the given position. No bounds checks are performed.

unsafeSwap :: (PrimMonad m, MVector u a) => u (PrimState m) a -> Int -> Int -> m ()Source

Swap the elements at the given positions. No bounds checks are performed.

Modifying vectors

Filling and copying

set :: (PrimMonad m, MVector u a) => u (PrimState m) a -> a -> m ()Source

Set all elements of the vector to the given value.

copy :: (PrimMonad m, Mixed u v a, Mixed u' v' a) => u (PrimState m) a -> u' (PrimState m) a -> m ()Source

Copy a vector. The two vectors must have the same length and may not overlap.

unsafeCopySource

Arguments

:: (PrimMonad m, Mixed u v a, Mixed u' v' a) 
=> u (PrimState m) a

target

-> u' (PrimState m) a

source

-> m () 

Copy a vector. The two vectors must have the same length and may not overlap. This is not checked.