dynamic-mvector-0.1.0.1: A wrapper around MVector that enables pushing, popping and extending.

Safe HaskellNone
LanguageHaskell2010

Data.Vector.Mutable.Dynamic

Contents

Description

A wrapper around MVector that enables pushing, popping and extending.

Synopsis

Documentation

data MVector s a Source

Mutable vector with dynamic behaviour living in the ST or IO monad.

Instances

Typeable (* -> * -> *) MVector 

Initialization

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

Create a new vector of given length. The elements are uninitialized and throw error upon accessing. The Int argument must be positive.

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

Returns a vector consisting of a value repeated the given times. Throws an error if the Int argument is negative.

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

New with the Int argument unchecked.

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

Replicate without checking the Int argument.

Accessing

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

Read a value from a location. Preforms bounds checking.

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

Write a value to a location. Performs bounds checking.

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

Read the front value. Throws an error if the vector is empty.

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

Read the back value. Throws an error if the vector is empty.

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

Read without bounds checking.

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

Write without bounds checking.

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

Read the front value without checking.

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

Read the back value without checking.

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

Set all the elements to a value.

Conversion

freeze :: PrimMonad m => MVector (PrimState m) a -> m (Vector a) Source

Create an immutable copy of the vector.

thaw :: PrimMonad m => Vector a -> m (MVector (PrimState m) a) Source

Create a mutable copy from an immutable vector.

frozen :: PrimMonad m => MVector (PrimState m) a -> (Vector a -> b) -> m b Source

Apply a function to an immutable copy of the vector.

unsafeFreeze :: PrimMonad m => MVector (PrimState m) a -> m (Vector a) Source

Convert a mutable vector to an immutable one without copying. The mutable vector shouldn't be accessed afterwards.

unsafeThaw :: PrimMonad m => Vector a -> m (MVector (PrimState m) a) Source

Convert an immutable vector to a mutable one wihout copying.

unsafeFrozen :: PrimMonad m => MVector (PrimState m) a -> (Vector a -> b) -> m b Source

Apply a function to the vector recast as immutable. This is usually unsafe if we later modify the vector.

Length information

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

Length of the vector.

null :: PrimMonad m => MVector (PrimState m) a -> m Bool Source

Check whether the vector is empty.

Copying

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

Create a copy from a mutable vector.

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

Move the contents of the right vector to the left one. Inputs must have the same length and must not overlap.

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

Move the contents of the right vector to the left one. The vectors must be the same length but may overlap.

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

Copy the contents of the right vector to the left one without checking length and overlapping.

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

Move the contents of the right vector to the left one. The vectors must have the same length and may overlap. Input lengths are unchecked.

Modification

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

Clear the vector of its contents, setting its length to 0.

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

Ensure that an amount of capacity is reserved in the vector. A no-op if there is already enough capacity. Throws an error if the argument is negative.

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

Ensure that an amount of capacity is reserved in the vector. A no-op if there is already enough capacity. The argument is unchecked.

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

Set reserved capacity to 0.

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

Increment the size of the vector and write a value to the back. Pushing to a slice will potentially overwrite the original vector's elements.

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

Read the back value and remove it from the vector. Throws an error if the vector is empty.

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

Read the back value and remove it from the vector, without checking.

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

Extend the vector on the left with the elements of the vector on right. | Extending a slice will potentially overwrite the original vector's elements.