Copyright | (c) Edward Kmett 2015 |
---|---|
License | BSD-style |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Portability | non-portable |
Safe Haskell | Unsafe |
Language | Haskell2010 |
Small primitive boxed arrays
- data SmallArray a = SmallArray (SmallArray# a)
- data SmallMutableArray s a = SmallMutableArray (SmallMutableArray# s a)
- newSmallArray :: PrimMonad m => Int -> a -> m (SmallMutableArray (PrimState m) a)
- readSmallArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> Int -> m a
- writeSmallArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> Int -> a -> m ()
- indexSmallArray :: SmallArray a -> Int -> a
- indexSmallArrayM :: Monad m => SmallArray a -> Int -> m a
- unsafeFreezeSmallArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> m (SmallArray a)
- unsafeThawSmallArray :: PrimMonad m => SmallArray a -> m (SmallMutableArray (PrimState m) a)
- sameSmallMutableArray :: SmallMutableArray s a -> SmallMutableArray s a -> Bool
- copySmallArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> Int -> SmallArray a -> Int -> Int -> m ()
- copySmallMutableArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> Int -> SmallMutableArray (PrimState m) a -> Int -> Int -> m ()
- cloneSmallArray :: SmallArray a -> Int -> Int -> SmallArray a
- cloneSmallMutableArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> Int -> Int -> m (SmallMutableArray (PrimState m) a)
- casSmallArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> Int -> a -> a -> m (Int, a)
- sizeOfSmallArray :: SmallArray a -> Int
- sizeOfSmallMutableArray :: SmallMutableArray s a -> Int
Documentation
data SmallArray a Source
Boxed arrays
Monad SmallArray Source | |
Functor SmallArray Source | |
Applicative SmallArray Source | |
Foldable SmallArray Source | |
Traversable SmallArray Source | |
MonadZip SmallArray Source | |
Alternative SmallArray Source | |
MonadPlus SmallArray Source | |
IsList (SmallArray a) Source | |
Eq a => Eq (SmallArray a) Source | |
Data a => Data (SmallArray a) Source | |
Ord a => Ord (SmallArray a) Source | |
Read a => Read (SmallArray a) Source | |
Show a => Show (SmallArray a) Source | |
Monoid (SmallArray a) Source | |
NFData a => NFData (SmallArray a) Source | |
AsEmpty (SmallArray a) Source | |
Ixed (SmallArray a) Source | |
Snoc (SmallArray a) (SmallArray b) a b Source | |
Cons (SmallArray a) (SmallArray b) a b Source | |
type Item (SmallArray a) = a Source | |
type IxValue (SmallArray a) = a Source | |
type Index (SmallArray a) = Int Source |
data SmallMutableArray s a Source
Mutable boxed arrays associated with a primitive state token.
Eq (SmallMutableArray s a) Source |
newSmallArray :: PrimMonad m => Int -> a -> m (SmallMutableArray (PrimState m) a) Source
Create a new mutable array of the specified size and initialise all elements with the given value.
readSmallArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> Int -> m a Source
Read a value from the array at the given index.
writeSmallArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> Int -> a -> m () Source
Write a value to the array at the given index.
indexSmallArray :: SmallArray a -> Int -> a Source
Read a value from the immutable array at the given index.
indexSmallArrayM :: Monad m => SmallArray a -> Int -> m a Source
Monadically read a value from the immutable array at the given index. This allows us to be strict in the array while remaining lazy in the read element which is very useful for collective operations. Suppose we want to copy an array. We could do something like this:
copy marr arr ... = do ... writeSmallArray marr i (indexSmallArray arr i) ... ...
But since primitive arrays are lazy, the calls to indexSmallArray
will not be
evaluated. Rather, marr
will be filled with thunks each of which would
retain a reference to arr
. This is definitely not what we want!
With indexSmallArrayM
, we can instead write
copy marr arr ... = do ... x <- indexSmallArrayM arr i writeSmallArray marr i x ...
Now, indexing is executed immediately although the returned element is still not evaluated.
unsafeFreezeSmallArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> m (SmallArray a) Source
Convert a mutable array to an immutable one without copying. The array should not be modified after the conversion.
unsafeThawSmallArray :: PrimMonad m => SmallArray a -> m (SmallMutableArray (PrimState m) a) Source
Convert an immutable array to an mutable one without copying. The immutable array should not be used after the conversion.
sameSmallMutableArray :: SmallMutableArray s a -> SmallMutableArray s a -> Bool Source
Check whether the two arrays refer to the same memory block.
:: PrimMonad m | |
=> SmallMutableArray (PrimState m) a | destination array |
-> Int | offset into destination array |
-> SmallArray a | source array |
-> Int | offset into source array |
-> Int | number of elements to copy |
-> m () |
Copy a slice of an immutable array to a mutable array.
:: PrimMonad m | |
=> SmallMutableArray (PrimState m) a | destination array |
-> Int | offset into destination array |
-> SmallMutableArray (PrimState m) a | source array |
-> Int | offset into source array |
-> Int | number of elements to copy |
-> m () |
Copy a slice of a mutable array to another array. The two arrays may not be the same.
:: SmallArray a | source array |
-> Int | offset into destination array |
-> Int | number of elements to copy |
-> SmallArray a |
Return a newly allocated SmallArray with the specified subrange of the provided SmallArray. The provided SmallArray should contain the full subrange specified by the two Ints, but this is not checked.
:: PrimMonad m | |
=> SmallMutableArray (PrimState m) a | source array |
-> Int | offset into destination array |
-> Int | number of elements to copy |
-> m (SmallMutableArray (PrimState m) a) |
Return a newly allocated SmallMutableArray. with the specified subrange of the provided SmallMutableArray. The provided SmallMutableArray should contain the full subrange specified by the two Ints, but this is not checked.
casSmallArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> Int -> a -> a -> m (Int, a) Source
Perform an unsafe, machine-level atomic compare and swap on an element within an array.
sizeOfSmallArray :: SmallArray a -> Int Source
sizeOfSmallMutableArray :: SmallMutableArray s a -> Int Source