{-# language BangPatterns #-}
{-# language MagicHash #-}
{-# language RankNTypes #-}
{-# language ScopedTypeVariables #-}
{-# language TypeFamilies #-}
{-# language UnboxedTuples #-}
{-# language RoleAnnotations #-}
module Data.Primitive.Unlifted.Array
(
A.UnliftedArray_(..)
, A.UnliftedArray
, A.MutableUnliftedArray_(..)
, A.MutableUnliftedArray
, newUnliftedArray
, unsafeNewUnliftedArray
, A.sizeofUnliftedArray
, A.sizeofMutableUnliftedArray
, A.sameMutableUnliftedArray
, writeUnliftedArray
, readUnliftedArray
, A.indexUnliftedArray
, unsafeFreezeUnliftedArray
, freezeUnliftedArray
, thawUnliftedArray
, unsafeThawUnliftedArray
, setUnliftedArray
, copyUnliftedArray
, copyMutableUnliftedArray
, A.cloneUnliftedArray
, cloneMutableUnliftedArray
, A.emptyUnliftedArray
, A.singletonUnliftedArray
, A.runUnliftedArray
, A.dupableRunUnliftedArray
, A.unliftedArrayToList
, A.unliftedArrayFromList
, A.unliftedArrayFromListN
, A.foldrUnliftedArray
, A.foldrUnliftedArray'
, A.foldlUnliftedArray
, A.foldlUnliftedArray'
, A.foldlUnliftedArrayM'
, A.traverseUnliftedArray_
, A.itraverseUnliftedArray_
, A.mapUnliftedArray
) where
import Control.Monad.Primitive (PrimMonad,PrimState,stToPrim)
import Data.Primitive.Unlifted.Class (PrimUnlifted (..))
import qualified Data.Primitive.Unlifted.Array.ST as A
import Data.Primitive.Unlifted.Array.ST (UnliftedArray, MutableUnliftedArray)
newUnliftedArray
:: (PrimMonad m, PrimUnlifted a)
=> Int
-> a
-> m (MutableUnliftedArray (PrimState m) a)
newUnliftedArray :: forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
Int -> a -> m (MutableUnliftedArray (PrimState m) a)
newUnliftedArray Int
len a
v = ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a))
-> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall a b. (a -> b) -> a -> b
$ Int -> a -> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
forall a s.
PrimUnlifted a =>
Int -> a -> ST s (MutableUnliftedArray s a)
A.newUnliftedArray Int
len a
v
{-# inline newUnliftedArray #-}
setUnliftedArray
:: (PrimMonad m, PrimUnlifted a)
=> MutableUnliftedArray (PrimState m) a
-> a
-> Int
-> Int
-> m ()
{-# inline setUnliftedArray #-}
setUnliftedArray :: forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> a -> Int -> Int -> m ()
setUnliftedArray MutableUnliftedArray (PrimState m) a
mua a
v Int
off Int
len = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ MutableUnliftedArray (PrimState m) a
-> a -> Int -> Int -> ST (PrimState m) ()
forall a s.
PrimUnlifted a =>
MutableUnliftedArray s a -> a -> Int -> Int -> ST s ()
A.setUnliftedArray MutableUnliftedArray (PrimState m) a
mua a
v Int
off Int
len
writeUnliftedArray :: (PrimMonad m, PrimUnlifted a)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> a
-> m ()
{-# inline writeUnliftedArray #-}
writeUnliftedArray :: forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray MutableUnliftedArray (PrimState m) a
mary Int
ix a
a = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ MutableUnliftedArray (PrimState m) a
-> Int -> a -> ST (PrimState m) ()
forall a s.
PrimUnlifted a =>
MutableUnliftedArray s a -> Int -> a -> ST s ()
A.writeUnliftedArray MutableUnliftedArray (PrimState m) a
mary Int
ix a
a
readUnliftedArray :: (PrimMonad m, PrimUnlifted a)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> m a
{-# inline readUnliftedArray #-}
readUnliftedArray :: forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> m a
readUnliftedArray MutableUnliftedArray (PrimState m) a
mary Int
ix = ST (PrimState m) a -> m a
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) a -> m a) -> ST (PrimState m) a -> m a
forall a b. (a -> b) -> a -> b
$ MutableUnliftedArray (PrimState m) a -> Int -> ST (PrimState m) a
forall a s.
PrimUnlifted a =>
MutableUnliftedArray s a -> Int -> ST s a
A.readUnliftedArray MutableUnliftedArray (PrimState m) a
mary Int
ix
unsafeFreezeUnliftedArray
:: PrimMonad m
=> MutableUnliftedArray (PrimState m) a
-> m (UnliftedArray a)
unsafeFreezeUnliftedArray :: forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
unsafeFreezeUnliftedArray MutableUnliftedArray (PrimState m) a
mary = ST (PrimState m) (UnliftedArray a) -> m (UnliftedArray a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (UnliftedArray a) -> m (UnliftedArray a))
-> ST (PrimState m) (UnliftedArray a) -> m (UnliftedArray a)
forall a b. (a -> b) -> a -> b
$ MutableUnliftedArray (PrimState m) a
-> ST (PrimState m) (UnliftedArray a)
forall s a. MutableUnliftedArray s a -> ST s (UnliftedArray a)
A.unsafeFreezeUnliftedArray MutableUnliftedArray (PrimState m) a
mary
{-# inline unsafeFreezeUnliftedArray #-}
copyUnliftedArray
:: PrimMonad m
=> MutableUnliftedArray (PrimState m) a
-> Int
-> UnliftedArray a
-> Int
-> Int
-> m ()
{-# inline copyUnliftedArray #-}
copyUnliftedArray :: forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int -> UnliftedArray a -> Int -> Int -> m ()
copyUnliftedArray MutableUnliftedArray (PrimState m) a
dst Int
doff UnliftedArray a
src Int
soff Int
ln = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ MutableUnliftedArray (PrimState m) a
-> Int -> UnliftedArray a -> Int -> Int -> ST (PrimState m) ()
forall s a.
MutableUnliftedArray s a
-> Int -> UnliftedArray a -> Int -> Int -> ST s ()
A.copyUnliftedArray MutableUnliftedArray (PrimState m) a
dst Int
doff UnliftedArray a
src Int
soff Int
ln
copyMutableUnliftedArray
:: PrimMonad m
=> MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m ()
{-# inline copyMutableUnliftedArray #-}
copyMutableUnliftedArray :: forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m ()
copyMutableUnliftedArray MutableUnliftedArray (PrimState m) a
dst Int
doff MutableUnliftedArray (PrimState m) a
src Int
soff Int
ln = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> ST (PrimState m) ()
forall s a.
MutableUnliftedArray s a
-> Int -> MutableUnliftedArray s a -> Int -> Int -> ST s ()
A.copyMutableUnliftedArray MutableUnliftedArray (PrimState m) a
dst Int
doff MutableUnliftedArray (PrimState m) a
src Int
soff Int
ln
freezeUnliftedArray
:: PrimMonad m
=> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m (UnliftedArray a)
freezeUnliftedArray :: forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int -> Int -> m (UnliftedArray a)
freezeUnliftedArray MutableUnliftedArray (PrimState m) a
mary Int
off Int
len = ST (PrimState m) (UnliftedArray a) -> m (UnliftedArray a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (UnliftedArray a) -> m (UnliftedArray a))
-> ST (PrimState m) (UnliftedArray a) -> m (UnliftedArray a)
forall a b. (a -> b) -> a -> b
$ MutableUnliftedArray (PrimState m) a
-> Int -> Int -> ST (PrimState m) (UnliftedArray a)
forall s a.
MutableUnliftedArray s a -> Int -> Int -> ST s (UnliftedArray a)
A.freezeUnliftedArray MutableUnliftedArray (PrimState m) a
mary Int
off Int
len
{-# inline freezeUnliftedArray #-}
thawUnliftedArray
:: PrimMonad m
=> UnliftedArray a
-> Int
-> Int
-> m (MutableUnliftedArray (PrimState m) a)
{-# inline thawUnliftedArray #-}
thawUnliftedArray :: forall (m :: * -> *) a.
PrimMonad m =>
UnliftedArray a
-> Int -> Int -> m (MutableUnliftedArray (PrimState m) a)
thawUnliftedArray UnliftedArray a
ary Int
off Int
len = ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a))
-> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall a b. (a -> b) -> a -> b
$ UnliftedArray a
-> Int
-> Int
-> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
forall a s.
UnliftedArray a -> Int -> Int -> ST s (MutableUnliftedArray s a)
A.thawUnliftedArray UnliftedArray a
ary Int
off Int
len
unsafeThawUnliftedArray
:: PrimMonad m
=> UnliftedArray a
-> m (MutableUnliftedArray (PrimState m) a)
{-# inline unsafeThawUnliftedArray #-}
unsafeThawUnliftedArray :: forall (m :: * -> *) a.
PrimMonad m =>
UnliftedArray a -> m (MutableUnliftedArray (PrimState m) a)
unsafeThawUnliftedArray UnliftedArray a
ary = ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a))
-> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall a b. (a -> b) -> a -> b
$ UnliftedArray a
-> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
forall a s. UnliftedArray a -> ST s (MutableUnliftedArray s a)
A.unsafeThawUnliftedArray UnliftedArray a
ary
unsafeNewUnliftedArray
:: PrimMonad m
=> Int
-> m (MutableUnliftedArray (PrimState m) a)
{-# inline unsafeNewUnliftedArray #-}
unsafeNewUnliftedArray :: forall (m :: * -> *) a.
PrimMonad m =>
Int -> m (MutableUnliftedArray (PrimState m) a)
unsafeNewUnliftedArray Int
len = ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a))
-> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall a b. (a -> b) -> a -> b
$ Int -> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
forall s a. Int -> ST s (MutableUnliftedArray s a)
A.unsafeNewUnliftedArray Int
len
cloneMutableUnliftedArray
:: (PrimMonad m)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m (MutableUnliftedArray (PrimState m) a)
{-# inline cloneMutableUnliftedArray #-}
cloneMutableUnliftedArray :: forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int -> Int -> m (MutableUnliftedArray (PrimState m) a)
cloneMutableUnliftedArray MutableUnliftedArray (PrimState m) a
mary Int
off Int
len = ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a))
-> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
-> m (MutableUnliftedArray (PrimState m) a)
forall a b. (a -> b) -> a -> b
$ MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> ST (PrimState m) (MutableUnliftedArray (PrimState m) a)
forall s a.
MutableUnliftedArray s a
-> Int -> Int -> ST s (MutableUnliftedArray s a)
A.cloneMutableUnliftedArray MutableUnliftedArray (PrimState m) a
mary Int
off Int
len