|Portability||non-portable (uses Data.Array.IArray)|
Functional arrays with constant-time update.
- data IOToDiffArray a i e
- type DiffArray = IOToDiffArray IOArray
- type DiffUArray = IOToDiffArray IOUArray
- module Data.Array.IArray
- newDiffArray :: (MArray a e IO, Ix i) => (i, i) -> [(Int, e)] -> IO (IOToDiffArray a i e)
- readDiffArray :: (MArray a e IO, Ix i) => IOToDiffArray a i e -> Int -> IO e
- replaceDiffArray :: (MArray a e IO, Ix i) => IOToDiffArray a i e -> [(Int, e)] -> IO (IOToDiffArray a i e)
Diff array types
Diff arrays have an immutable interface, but rely on internal
updates in place to provide fast functional update operator
// operator is applied to a diff array, its contents
are physically updated in place. The old array silently changes
its representation without changing the visible behavior:
it stores a link to the new current array along with the
difference to be applied to get the old contents.
So if a diff array is used in a single-threaded style,
// application the old version is no longer used,
a takes O(1) time and
a takes O(
Accessing elements of older versions gradually becomes slower.
Updating an array which is not current makes a physical copy.
The resulting array is unlinked from the old family. So you
can obtain a version which is guaranteed to be current and
thus have fast element access by
Type synonyms for the two most important IO array types.
Strict unboxed diff array, working only for elements
of primitive types but more compact and usually faster than
Overloaded immutable array interface