aivika-transformers-6.1: Transformers for the Aivika simulation library
CopyrightCopyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Simulation.Aivika.Trans.Vector

Description

Tested with: GHC 8.0.1

An imperative vector.

Synopsis

Documentation

data Vector m a Source #

Represents a resizable vector.

newVector :: MonadRef m => Simulation m (Vector m a) Source #

Create a new vector.

copyVector :: MonadRef m => Vector m a -> Event m (Vector m a) Source #

Copy the vector.

vectorCount :: MonadRef m => Vector m a -> Event m Int Source #

Return the element count.

appendVector :: MonadRef m => Vector m a -> a -> Event m () Source #

Add the specified element to the end of the vector.

readVector :: MonadRef m => Vector m a -> Int -> Event m a Source #

Read a value from the vector, where indices are started from 0.

writeVector :: MonadRef m => Vector m a -> Int -> a -> Event m () Source #

Set an array item at the specified index which is started from 0.

vectorBinarySearch :: (MonadRef m, Ord a) => Vector m a -> a -> Event m Int Source #

Return the index of the specified element using binary search; otherwise, a negated insertion index minus one: 0 -> -0 - 1, ..., i -> -i - 1, ....

vectorInsert :: MonadRef m => Vector m a -> Int -> a -> Event m () Source #

Insert the element in the vector at the specified index.

vectorDeleteAt :: MonadRef m => Vector m a -> Int -> Event m () Source #

Delete the element at the specified index.

vectorDeleteRange Source #

Arguments

:: MonadRef m 
=> Vector m a

the vector

-> Int

the start index

-> Int

the count of items to be removed

-> Event m () 

Delete the specified range of elements.

vectorDelete :: (MonadRef m, Eq a) => Vector m a -> a -> Event m Bool Source #

Remove the specified element and return a flag indicating whether the element was found and removed.

vectorDeleteBy :: MonadRef m => Vector m a -> (a -> Bool) -> Event m (Maybe a) Source #

Remove an element by the specified predicate and return the element if found.

vectorIndex :: (MonadRef m, Eq a) => Vector m a -> a -> Event m Int Source #

Return the index of the item or -1.

vectorIndexBy :: MonadRef m => Vector m a -> (a -> Bool) -> Event m Int Source #

Return an index of the item satisfying the predicate or -1.

vectorContains :: (MonadRef m, Eq a) => Vector m a -> a -> Event m Bool Source #

Detect whether the specified element is contained in the vector.

vectorContainsBy :: MonadRef m => Vector m a -> (a -> Bool) -> Event m (Maybe a) Source #

Detect whether an element satisfying the specified predicate is contained in the vector.

freezeVector :: MonadRef m => Vector m a -> Event m (Array Int a) Source #

Return the elements of the vector in an immutable array.