Safe Haskell | None |
---|---|

Language | Haskell2010 |

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

- data MVector s a
- type STVector = MVector
- type IOVector = MVector RealWorld
- new :: PrimMonad m => Int -> m (MVector (PrimState m) a)
- replicate :: PrimMonad m => Int -> a -> m (MVector (PrimState m) a)
- unsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) a)
- unsafeReplicate :: PrimMonad m => Int -> a -> m (MVector (PrimState m) a)
- read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a
- write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m ()
- readFront :: PrimMonad m => MVector (PrimState m) a -> m a
- readBack :: PrimMonad m => MVector (PrimState m) a -> m a
- unsafeRead :: PrimMonad m => MVector (PrimState m) a -> Int -> m a
- unsafeWrite :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m ()
- unsafeReadFront :: PrimMonad m => MVector (PrimState m) a -> m a
- unsafeReadBack :: PrimMonad m => MVector (PrimState m) a -> m a
- set :: PrimMonad m => MVector (PrimState m) a -> a -> m ()
- freeze :: PrimMonad m => MVector (PrimState m) a -> m (Vector a)
- thaw :: PrimMonad m => Vector a -> m (MVector (PrimState m) a)
- frozen :: PrimMonad m => MVector (PrimState m) a -> (Vector a -> b) -> m b
- unsafeFreeze :: PrimMonad m => MVector (PrimState m) a -> m (Vector a)
- unsafeThaw :: PrimMonad m => Vector a -> m (MVector (PrimState m) a)
- unsafeFrozen :: PrimMonad m => MVector (PrimState m) a -> (Vector a -> b) -> m b
- length :: PrimMonad m => MVector (PrimState m) a -> m Int
- null :: PrimMonad m => MVector (PrimState m) a -> m Bool
- capacity :: PrimMonad m => MVector (PrimState m) a -> m Int
- clone :: PrimMonad m => MVector (PrimState m) a -> m (MVector (PrimState m) a)
- copy :: PrimMonad m => MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
- move :: PrimMonad m => MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
- unsafeCopy :: PrimMonad m => MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
- unsafeMove :: PrimMonad m => MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
- clear :: PrimMonad m => MVector (PrimState m) a -> m ()
- reserve :: PrimMonad m => MVector (PrimState m) a -> Int -> m ()
- unsafeReserve :: PrimMonad m => MVector (PrimState m) a -> Int -> m ()
- trim :: PrimMonad m => MVector (PrimState m) a -> m ()
- pushBack :: PrimMonad m => MVector (PrimState m) a -> a -> m ()
- popBack :: PrimMonad m => MVector (PrimState m) a -> m a
- unsafePopBack :: PrimMonad m => MVector (PrimState m) a -> m a
- extend :: PrimMonad m => MVector (PrimState m) a -> MVector (PrimState m) a -> m ()

# Documentation

# 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.

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.

# 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

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

Number of elements that the vector currently have reserved space for.

# 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.

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.