ArrayRef-0.1.3.1: Unboxed references, dynamic arrays and moreSource codeContentsIndex
Data.ArrayBZ.Dynamic
PortabilityHugs/GHC
Stabilityexperimental
MaintainerBulat Ziganshin <Bulat.Ziganshin@gmail.com>
Contents
Operations
Array growing strategies
Description
Arrays with dynamically changed bounds in IO and ST monads.
Synopsis
data Dynamic r a i e
type DynamicIO = Dynamic IORef
type DynamicIOArray = DynamicIO IOArray
type DynamicIOUArray = DynamicIO IOUArray
type DynamicST s = Dynamic (STRef s)
type DynamicSTArray s = DynamicST s (STArray s)
type DynamicSTUArray s = DynamicST s (STUArray s)
type GrowBoundsF i = (i, i) -> i -> (i, i)
newDynamicArray :: (Ref t r, Ix i, MArray a e t) => GrowBoundsF i -> (i, i) -> e -> t (Dynamic r a i e)
newDynamicArray_ :: (Ref t r, Ix i, MArray a e t) => GrowBoundsF i -> (i, i) -> t (Dynamic r a i e)
resizeDynamicArray :: (Ix i, MArray a t t2, Ref t2 t1) => Dynamic t1 a i t -> (i, i) -> t2 ()
noGrow :: t -> t1 -> a
growMinimally :: Ix t => (t, t) -> t -> (t, t)
growTwoTimes :: (Num a, Ord a) => (a, a) -> a -> (a, a)
module Data.ArrayBZ.Internals.MArray
Documentation

Array with dynamically changed bounds can be created from any mutable array type by using type converter Dynamic. I have created synonyms for widely used array constructors, for example DynamicIOUArray Int Double. Dynamic array supports the same MArray and HasMutableBounds interfaces as other mutable arrays, but they don't support HasBounds interface. Dynamic array can be resized explicitly by operation resizeDynamicArray.

Dynamic array can also grow automatically when writeArray is used with index that is out of current array bounds. For this to work, array should be created using non-standard operations newDynamicArray or newDynamicArray_. The first argument of these operations is growing strategy, i.e. the function of type `GrowBoundsF i`, other arguments are the same as for newArray/newArray_. The predefined growing strategies include noGrow that disables automatic growing, growMinimally that extends array only to include new index and growTwoTimes that extend array at least 2 times each time it needs to grow.

When array grows, either explicitly or automatically, new elements are initialized with init value if this array was created by newArray/newDynamicArray.

data Dynamic r a i e Source
Representation of dynamic array. Includes * function to calculate new array bounds when it needs to grow * optional value used for initializing new elements when array grows * reference to current array contents
show/hide Instances
(HasMutableBounds a m, Ref m r) => HasMutableBounds (Dynamic r a) m
(MArray a e m, Ref m r) => MArray (Dynamic r a) e m
type DynamicIO = Dynamic IORefSource
Dynamic arrays in IO monad
type DynamicIOArray = DynamicIO IOArraySource
Dynamic version of IOArray
type DynamicIOUArray = DynamicIO IOUArraySource
Dynamic version of IOUArray
type DynamicST s = Dynamic (STRef s)Source
Dynamic arrays in ST monad
type DynamicSTArray s = DynamicST s (STArray s)Source
Dynamic version of STArray
type DynamicSTUArray s = DynamicST s (STUArray s)Source
Dynamic version of STUArray
type GrowBoundsF i = (i, i) -> i -> (i, i)Source
This type represents function that calculates new array bounds when it needs to grow
Operations
newDynamicArray :: (Ref t r, Ix i, MArray a e t) => GrowBoundsF i -> (i, i) -> e -> t (Dynamic r a i e)Source
Create new dynamic array with default value for new cells set to init. f is a growing strategy and may be noGrow, growMinimally or growTwoTimes
newDynamicArray_ :: (Ref t r, Ix i, MArray a e t) => GrowBoundsF i -> (i, i) -> t (Dynamic r a i e)Source
Create new dynamic array where all new cells will remain uninitialized. f is a growing strategy and may be noGrow, growMinimally or growTwoTimes
resizeDynamicArray :: (Ix i, MArray a t t2, Ref t2 t1) => Dynamic t1 a i t -> (i, i) -> t2 ()Source
Extend/shrink dynamic array to new bounds
Array growing strategies
noGrow :: t -> t1 -> aSource
No automatic growing at all. This growing method is compatible with any bounds type
growMinimally :: Ix t => (t, t) -> t -> (t, t)Source
Grow minimally - only to include new index in array bounds. This growing method is compatible with any bounds type
growTwoTimes :: (Num a, Ord a) => (a, a) -> a -> (a, a)Source
Grow number of elements at least 2 times. This growing method is compatible only with bounds belonging to class Num
module Data.ArrayBZ.Internals.MArray
Produced by Haddock version 2.4.2