|
Data.ArrayBZ.Dynamic | Portability | Hugs/GHC | Stability | experimental | Maintainer | Bulat Ziganshin <Bulat.Ziganshin@gmail.com> |
|
|
|
|
|
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.
|
|
|
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
| Instances | |
|
|
|
Dynamic arrays in IO monad
|
|
|
Dynamic version of IOArray
|
|
|
Dynamic version of IOUArray
|
|
|
Dynamic arrays in ST monad
|
|
|
Dynamic version of STArray
|
|
|
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
|
|
|
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
|
|
|
Create new dynamic array where all new cells will remain uninitialized.
f is a growing strategy and may be noGrow, growMinimally
or growTwoTimes
|
|
|
Extend/shrink dynamic array to new bounds
|
|
Array growing strategies
|
|
|
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 |