| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Primitive.Contiguous
Contents
Description
The contiguous typeclass parameterises over a contiguous array type. This allows us to have a common API to a number of contiguous array types and their mutable counterparts.
Synopsis
- size :: (Contiguous arr, Element arr b) => arr b -> Int
- sizeMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> m Int
- null :: Contiguous arr => arr b -> Bool
- index :: (Contiguous arr, Element arr b) => arr b -> Int -> b
- index# :: (Contiguous arr, Element arr b) => arr b -> Int -> (#b#)
- read :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m b
- indexM :: (Contiguous arr, Element arr b, Monad m) => arr b -> Int -> m b
- empty :: Contiguous arr => arr a
- new :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> m (Mutable arr (PrimState m) b)
- singleton :: (Contiguous arr, Element arr a) => a -> arr a
- doubleton :: (Contiguous arr, Element arr a) => a -> a -> arr a
- tripleton :: (Contiguous arr, Element arr a) => a -> a -> a -> arr a
- replicate :: (Contiguous arr, Element arr a) => Int -> a -> arr a
- replicateMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> b -> m (Mutable arr (PrimState m) b)
- generate :: (Contiguous arr, Element arr a) => Int -> (Int -> a) -> arr a
- generateMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> a) -> m (Mutable arr (PrimState m) a)
- iterateN :: (Contiguous arr, Element arr a) => Int -> (a -> a) -> a -> arr a
- iterateMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> a) -> a -> m (Mutable arr (PrimState m) a)
- write :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> b -> m ()
- replicateMutableM :: (PrimMonad m, Contiguous arr, Element arr a) => Int -> m a -> m (Mutable arr (PrimState m) a)
- generateMutableM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> m a) -> m (Mutable arr (PrimState m) a)
- iterateMutableNM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> m a) -> a -> m (Mutable arr (PrimState m) a)
- create :: (Contiguous arr, Element arr a) => (forall s. ST s (Mutable arr s a)) -> arr a
- createT :: (Contiguous arr, Element arr a, Traversable f) => (forall s. ST s (f (Mutable arr s a))) -> f (arr a)
- unfoldr :: (Contiguous arr, Element arr a) => (b -> Maybe (a, b)) -> b -> arr a
- unfoldrN :: (Contiguous arr, Element arr a) => Int -> (b -> Maybe (a, b)) -> b -> arr a
- unfoldrMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (b -> Maybe (a, b)) -> b -> m (Mutable arr (PrimState m) a)
- enumFromN :: (Contiguous arr, Element arr a, Enum a) => a -> Int -> arr a
- enumFromMutableN :: (Contiguous arr, Element arr a, PrimMonad m, Enum a) => a -> Int -> m (Mutable arr (PrimState m) a)
- append :: (Contiguous arr, Element arr a) => arr a -> arr a -> arr a
- reverse :: (Contiguous arr, Element arr a) => arr a -> arr a
- reverseMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m ()
- resize :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m (Mutable arr (PrimState m) b)
- map :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c
- map' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c
- mapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m ()
- mapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (a -> a) -> Mutable arr (PrimState m) a -> m ()
- imap :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c
- imap' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c
- imapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m ()
- imapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m ()
- modify :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m ()
- modify' :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m ()
- mapMaybe :: forall arr1 arr2 a b. (Contiguous arr1, Element arr1 a, Contiguous arr2, Element arr2 b) => (a -> Maybe b) -> arr1 a -> arr2 b
- filter :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> arr a
- ifilter :: (Contiguous arr, Element arr a) => (Int -> a -> Bool) -> arr a -> arr a
- equals :: (Contiguous arr, Element arr b, Eq b) => arr b -> arr b -> Bool
- equalsMutable :: Contiguous arr => Mutable arr s a -> Mutable arr s a -> Bool
- same :: Contiguous arr => arr a -> arr a -> Bool
- foldl :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b
- foldl' :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b
- foldr :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b
- foldr' :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b
- foldMap :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m
- foldMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m
- foldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m
- ifoldl' :: (Contiguous arr, Element arr a) => (b -> Int -> a -> b) -> b -> arr a -> b
- ifoldr' :: (Contiguous arr, Element arr a) => (Int -> a -> b -> b) -> b -> arr a -> b
- ifoldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (Int -> a -> m) -> arr a -> m
- ifoldlMap1' :: (Contiguous arr, Element arr a, Semigroup m) => (Int -> a -> m) -> arr a -> m
- foldlM' :: (Contiguous arr, Element arr a, Monad m) => (b -> a -> m b) -> b -> arr a -> m b
- traverse :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => (a -> f b) -> arr a -> f (arr b)
- traverse_ :: (Contiguous arr, Element arr a, Applicative f) => (a -> f b) -> arr a -> f ()
- itraverse :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => (Int -> a -> f b) -> arr a -> f (arr b)
- itraverse_ :: (Contiguous arr, Element arr a, Applicative f) => (Int -> a -> f b) -> arr a -> f ()
- traverseP :: (PrimMonad m, Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (a -> m b) -> arr1 a -> m (arr2 b)
- fromList :: (Contiguous arr, Element arr a) => [a] -> arr a
- fromListN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a
- fromListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => [a] -> m (Mutable arr (PrimState m) a)
- fromListMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a)
- unsafeFromListN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a
- unsafeFromListReverseN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a
- unsafeFromListReverseMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a)
- toList :: (Contiguous arr, Element arr a) => arr a -> [a]
- toListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m [a]
- convert :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 b) => arr1 b -> arr2 b
- lift :: Contiguous arr => ArrayArray# -> arr b
- unlift :: Contiguous arr => arr b -> ArrayArray#
- clone :: (Contiguous arr, Element arr b) => arr b -> Int -> Int -> arr b
- cloneMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (Mutable arr (PrimState m) b)
- copy :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()
- copyMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m ()
- freeze :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)
- thaw :: (Contiguous arr, PrimMonad m, Element arr b) => arr b -> Int -> Int -> m (Mutable arr (PrimState m) b)
- unsafeFreeze :: (Contiguous arr, PrimMonad m) => Mutable arr (PrimState m) b -> m (arr b)
- liftHashWithSalt :: (Contiguous arr, Element arr a) => (Int -> a -> Int) -> Int -> arr a -> Int
- rnf :: (Contiguous arr, NFData a, Element arr a) => arr a -> ()
- class Contiguous (arr :: Type -> Type) where
- class Always a
Accessors
Length Information
sizeMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> m Int Source #
The size of the mutable array
null :: Contiguous arr => arr b -> Bool Source #
Test whether the array is empty.
Indexing
index :: (Contiguous arr, Element arr b) => arr b -> Int -> b Source #
Index into an array at the given index.
index# :: (Contiguous arr, Element arr b) => arr b -> Int -> (#b#) Source #
Index into an array at the given index, yielding an unboxed one-tuple of the element.
read :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m b Source #
Read a mutable array at the given index.
Monadic indexing
indexM :: (Contiguous arr, Element arr b, Monad m) => arr b -> Int -> m b Source #
Indexing in a monad.
The monad allows operations to be strict in the array when necessary. Suppose array copying is implemented like this:
copy mv v = ... write mv i (v ! i) ...
For lazy arrays, v ! i would not be not be evaluated,
which means that mv would unnecessarily retain a reference
to v in each element written.
With indexM, copying can be implemented like this instead:
copy mv v = ... do x <- indexM v i write mv i x
Here, no references to v are retained because indexing
(but not the elements) is evaluated eagerly.
Construction
Initialisation
empty :: Contiguous arr => arr a Source #
The empty array.
new :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> m (Mutable arr (PrimState m) b) Source #
Allocate a new mutable array of the given size.
singleton :: (Contiguous arr, Element arr a) => a -> arr a Source #
Create a singleton array.
doubleton :: (Contiguous arr, Element arr a) => a -> a -> arr a Source #
Create a doubleton array.
tripleton :: (Contiguous arr, Element arr a) => a -> a -> a -> arr a Source #
Create a tripleton array.
replicate :: (Contiguous arr, Element arr a) => Int -> a -> arr a Source #
is an array of length replicate n xn with x the value of every element.
replicateMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> b -> m (Mutable arr (PrimState m) b) Source #
is a mutable array of length replicateMutable n xn with x the value of every element.
generate :: (Contiguous arr, Element arr a) => Int -> (Int -> a) -> arr a Source #
Construct an array of the given length by applying the function to each index.
generateMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> a) -> m (Mutable arr (PrimState m) a) Source #
Construct a mutable array of the given length by applying the function to each index.
iterateMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> a) -> a -> m (Mutable arr (PrimState m) a) Source #
Apply a function n times to a value and construct a mutable array
where each consecutive element is the result of an additional
application of this function. The zeroth element is the original value.
write :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> b -> m () Source #
Write to a mutable array at the given index.
Monadic initialisation
replicateMutableM :: (PrimMonad m, Contiguous arr, Element arr a) => Int -> m a -> m (Mutable arr (PrimState m) a) Source #
performs the action n times, gathering the results.replicateMutableM n act
generateMutableM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> m a) -> m (Mutable arr (PrimState m) a) Source #
Construct a mutable array of the given length by applying the monadic action to each index.
iterateMutableNM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> m a) -> a -> m (Mutable arr (PrimState m) a) Source #
Apply a monadic function n times to a value and construct a mutable array
where each consecutive element is the result of an additional
application of this function. The zeroth element is the original value.
create :: (Contiguous arr, Element arr a) => (forall s. ST s (Mutable arr s a)) -> arr a Source #
Execute the monad action and freeze the resulting array.
createT :: (Contiguous arr, Element arr a, Traversable f) => (forall s. ST s (f (Mutable arr s a))) -> f (arr a) Source #
Execute the monadic action and freeze the resulting array.
Unfolding
unfoldrMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (b -> Maybe (a, b)) -> b -> m (Mutable arr (PrimState m) a) Source #
Enumeration
enumFromMutableN :: (Contiguous arr, Element arr a, PrimMonad m, Enum a) => a -> Int -> m (Mutable arr (PrimState m) a) Source #
Concatenation
append :: (Contiguous arr, Element arr a) => arr a -> arr a -> arr a Source #
Append two arrays.
Modifying arrays
Permutations
reverse :: (Contiguous arr, Element arr a) => arr a -> arr a Source #
Reverse the elements of an array.
reverseMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m () Source #
Reverse the elements of a mutable array, in-place.
Resizing
resize :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m (Mutable arr (PrimState m) b) Source #
Resize an array into one with the given size.
Elementwise operations
Mapping
map :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c Source #
Map over the elements of an array.
Note that because a new array must be created, the resulting array type can be different than the original.
map' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c Source #
Map strictly over the elements of an array.
Note that because a new array must be created, the resulting array type can be different than the original.
mapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Map over a mutable array, modifying the elements in place.
mapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Strictly map over a mutable array, modifying the elements in place.
imap :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c Source #
Map over the elements of an array with the index.
imap' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c Source #
Map strictly over the elements of an array with the index.
Note that because a new array must be created, the resulting array type can be different than the original.
imapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Map over a mutable array with indices, modifying the elements in place.
imapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Strictly map over a mutable array with indices, modifying the elements in place.
modify :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Modify the elements of a mutable array in-place.
modify' :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Strictly modify the elements of a mutable array in-place.
mapMaybe :: forall arr1 arr2 a b. (Contiguous arr1, Element arr1 a, Contiguous arr2, Element arr2 b) => (a -> Maybe b) -> arr1 a -> arr2 b Source #
Working with predicates
Filtering
filter :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> arr a Source #
Drop elements that do not satisfy the predicate.
ifilter :: (Contiguous arr, Element arr a) => (Int -> a -> Bool) -> arr a -> arr a Source #
Drop elements that do not satisfy the predicate which is applied to values and their indices.
Comparing for equality
equals :: (Contiguous arr, Element arr b, Eq b) => arr b -> arr b -> Bool Source #
Test the two arrays for equality.
equalsMutable :: Contiguous arr => Mutable arr s a -> Mutable arr s a -> Bool Source #
Test the two mutable arrays for pointer equality. Does not check equality of elements.
same :: Contiguous arr => arr a -> arr a -> Bool Source #
This function does not behave deterministically. Optimization level and
inlining can affect its results. However, the one thing that can be counted
on is that if it returns True, the two immutable arrays are definitely the
same. This is useful as shortcut for equality tests. However, keep in mind
that a result of False tells us nothing about the arguments.
Folds
foldl :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b Source #
Left fold over the elements of an array.
foldl' :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b Source #
Strict left fold over the elements of an array.
foldr :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b Source #
Right fold over the element of an array.
foldr' :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b Source #
Strict right fold over the elements of an array.
foldMap :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m Source #
Monoidal fold over the element of an array.
foldMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m Source #
Strict monoidal fold over the elements of an array.
foldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m Source #
Strict left monoidal fold over the elements of an array.
ifoldl' :: (Contiguous arr, Element arr a) => (b -> Int -> a -> b) -> b -> arr a -> b Source #
Strict left fold over the elements of an array, where the accumulating function cares about the index of the element.
ifoldr' :: (Contiguous arr, Element arr a) => (Int -> a -> b -> b) -> b -> arr a -> b Source #
Strict right fold over the elements of an array, where the accumulating function cares about the index of the element.
ifoldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (Int -> a -> m) -> arr a -> m Source #
Strict monoidal fold over the elements of an array.
ifoldlMap1' :: (Contiguous arr, Element arr a, Semigroup m) => (Int -> a -> m) -> arr a -> m Source #
Strict monoidal fold over the elements of an array.
foldlM' :: (Contiguous arr, Element arr a, Monad m) => (b -> a -> m b) -> b -> arr a -> m b Source #
Strict left monadic fold over the elements of an array.
Traversals
traverse :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => (a -> f b) -> arr a -> f (arr b) Source #
Map each element of the array to an action, evaluate these
actions from left to right, and collect the results.
For a version that ignores the results, see traverse_.
traverse_ :: (Contiguous arr, Element arr a, Applicative f) => (a -> f b) -> arr a -> f () Source #
Map each element of the array to an action, evaluate these
actions from left to right, and ignore the results.
For a version that doesn't ignore the results, see traverse.
itraverse :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => (Int -> a -> f b) -> arr a -> f (arr b) Source #
Map each element of the array and its index to an action, evaluating these actions from left to right.
itraverse_ :: (Contiguous arr, Element arr a, Applicative f) => (Int -> a -> f b) -> arr a -> f () Source #
Map each element of the array and its index to an action,
evaluate these actions from left to right, and ignore the results.
For a version that doesn't ignore the results, see itraverse.
traverseP :: (PrimMonad m, Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (a -> m b) -> arr1 a -> m (arr2 b) Source #
Map each element of the array to an action, evaluate these actions from left to right, and collect the results in a new array.
Conversions
Lists
fromList :: (Contiguous arr, Element arr a) => [a] -> arr a Source #
Convert a list into an array.
fromListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => [a] -> m (Mutable arr (PrimState m) a) Source #
Convert a list into a mutable array of the given length.
fromListMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a) Source #
Arguments
| :: (Contiguous arr, Element arr a) | |
| => Int | length of list |
| -> [a] | list |
| -> arr a |
Create an array from a list. If the given length does not match the actual length, this function has undefined behavior.
unsafeFromListReverseN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a Source #
Create an array from a list, reversing the order of the elements. If the given length does not match the actual length, this function has undefined behavior.
unsafeFromListReverseMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a) Source #
Create a mutable array from a list, reversing the order of the elements. If the given length does not match the actual length, this function has undefined behavior.
toList :: (Contiguous arr, Element arr a) => arr a -> [a] Source #
Convert an array to a list.
toListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m [a] Source #
Convert a mutable array to a list.
Other array types
convert :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 b) => arr1 b -> arr2 b Source #
Convert one type of array into another.
lift :: Contiguous arr => ArrayArray# -> arr b Source #
Lift an ArrayArray# into an array.
unlift :: Contiguous arr => arr b -> ArrayArray# Source #
Unlift an array into an ArrayArray#.
Between mutable and immutable variants
clone :: (Contiguous arr, Element arr b) => arr b -> Int -> Int -> arr b Source #
Clone a slice of an array.
cloneMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (Mutable arr (PrimState m) b) Source #
Clone a slice of a mutable array.
Arguments
| :: (Contiguous arr, PrimMonad m, Element arr b) | |
| => Mutable arr (PrimState m) b | destination array |
| -> Int | offset into destination array |
| -> arr b | source array |
| -> Int | offset into source array |
| -> Int | number of elements to copy |
| -> m () |
Copy a slice of an array into a mutable array.
Arguments
| :: (Contiguous arr, PrimMonad m, Element arr b) | |
| => Mutable arr (PrimState m) b | destination array |
| -> Int | offset into destination array |
| -> Mutable arr (PrimState m) b | source array |
| -> Int | offset into source array |
| -> Int | number of elements to copy |
| -> m () |
Copy a slice of a mutable array into another mutable array. In the case that the destination and source arrays are the same, the regions may overlap.
freeze :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (arr b) Source #
Turn a mutable array into an immutable one with copying, using a slice of the mutable array.
thaw :: (Contiguous arr, PrimMonad m, Element arr b) => arr b -> Int -> Int -> m (Mutable arr (PrimState m) b) Source #
Copy a slice of an immutable array into a new mutable array.
unsafeFreeze :: (Contiguous arr, PrimMonad m) => Mutable arr (PrimState m) b -> m (arr b) Source #
Turn a mutable array into an immutable one without copying. The mutable array should not be used after this conversion.
Hashing
liftHashWithSalt :: (Contiguous arr, Element arr a) => (Int -> a -> Int) -> Int -> arr a -> Int Source #
Lift an accumulating hash function over the elements of the array, returning the final accumulated hash.
Forcing an array and its contents
rnf :: (Contiguous arr, NFData a, Element arr a) => arr a -> () Source #
Reduce the array and all of its elements to WHNF.
Classes
class Contiguous (arr :: Type -> Type) Source #
The Contiguous typeclass as an interface to a multitude of
contiguous structures.
Minimal complete definition
empty, null, new, replicateMutable, index, index#, indexM, read, write, resize, size, sizeMutable, unsafeFreeze, freeze, thaw, copy, copyMutable, clone, cloneMutable, equals, equalsMutable, unlift, lift, singleton, doubleton, tripleton, rnf
Associated Types
type Mutable arr = (r :: Type -> Type -> Type) | r -> arr Source #
The Mutable counterpart to the array.
type Element arr :: Type -> Constraint Source #
The constraint needed to store elements in the array.
Instances
A typeclass that is satisfied by all types. This is used
used to provide a fake constraint for Array and SmallArray.
Instances
| Always a Source # | |
Defined in Data.Primitive.Contiguous | |