module Z.Data.Array.UnliftedArray where
import Control.Monad.Primitive
import Data.Primitive.PrimArray (PrimArray(..),MutablePrimArray(..))
import Data.Primitive.ByteArray (ByteArray(..),MutableByteArray(..))
import GHC.MVar (MVar(..))
import GHC.IORef (IORef(..))
import GHC.STRef (STRef(..))
import GHC.Exts
import GHC.IO.Unsafe
class PrimUnlifted a where
writeUnliftedArray# :: MutableArrayArray# s -> Int# -> a -> State# s -> State# s
readUnliftedArray# :: MutableArrayArray# s -> Int# -> State# s -> (# State# s, a #)
indexUnliftedArray# :: ArrayArray# -> Int# -> a
instance PrimUnlifted (PrimArray a) where
{-# inline writeUnliftedArray# #-}
{-# inline readUnliftedArray# #-}
{-# inline indexUnliftedArray# #-}
writeUnliftedArray# :: MutableArrayArray# s -> Int# -> PrimArray a -> State# s -> State# s
writeUnliftedArray# MutableArrayArray# s
a Int#
i (PrimArray ByteArray#
x) = MutableArrayArray# s -> Int# -> ByteArray# -> State# s -> State# s
forall d.
MutableArrayArray# d -> Int# -> ByteArray# -> State# d -> State# d
writeByteArrayArray# MutableArrayArray# s
a Int#
i ByteArray#
x
readUnliftedArray# :: MutableArrayArray# s
-> Int# -> State# s -> (# State# s, PrimArray a #)
readUnliftedArray# MutableArrayArray# s
a Int#
i State# s
s0 = case MutableArrayArray# s
-> Int# -> State# s -> (# State# s, ByteArray# #)
forall d.
MutableArrayArray# d
-> Int# -> State# d -> (# State# d, ByteArray# #)
readByteArrayArray# MutableArrayArray# s
a Int#
i State# s
s0 of
(# State# s
s1, ByteArray#
x #) -> (# State# s
s1, ByteArray# -> PrimArray a
forall a. ByteArray# -> PrimArray a
PrimArray ByteArray#
x #)
indexUnliftedArray# :: ArrayArray# -> Int# -> PrimArray a
indexUnliftedArray# ArrayArray#
a Int#
i = ByteArray# -> PrimArray a
forall a. ByteArray# -> PrimArray a
PrimArray (ArrayArray# -> Int# -> ByteArray#
indexByteArrayArray# ArrayArray#
a Int#
i)
instance PrimUnlifted ByteArray where
{-# inline writeUnliftedArray# #-}
{-# inline readUnliftedArray# #-}
{-# inline indexUnliftedArray# #-}
writeUnliftedArray# :: MutableArrayArray# s -> Int# -> ByteArray -> State# s -> State# s
writeUnliftedArray# MutableArrayArray# s
a Int#
i (ByteArray ByteArray#
x) = MutableArrayArray# s -> Int# -> ByteArray# -> State# s -> State# s
forall d.
MutableArrayArray# d -> Int# -> ByteArray# -> State# d -> State# d
writeByteArrayArray# MutableArrayArray# s
a Int#
i ByteArray#
x
readUnliftedArray# :: MutableArrayArray# s
-> Int# -> State# s -> (# State# s, ByteArray #)
readUnliftedArray# MutableArrayArray# s
a Int#
i State# s
s0 = case MutableArrayArray# s
-> Int# -> State# s -> (# State# s, ByteArray# #)
forall d.
MutableArrayArray# d
-> Int# -> State# d -> (# State# d, ByteArray# #)
readByteArrayArray# MutableArrayArray# s
a Int#
i State# s
s0 of
(# State# s
s1, ByteArray#
x #) -> (# State# s
s1, ByteArray# -> ByteArray
ByteArray ByteArray#
x #)
indexUnliftedArray# :: ArrayArray# -> Int# -> ByteArray
indexUnliftedArray# ArrayArray#
a Int#
i = ByteArray# -> ByteArray
ByteArray (ArrayArray# -> Int# -> ByteArray#
indexByteArrayArray# ArrayArray#
a Int#
i)
instance PrimUnlifted (MutableByteArray s) where
{-# inline writeUnliftedArray# #-}
{-# inline readUnliftedArray# #-}
{-# inline indexUnliftedArray# #-}
writeUnliftedArray# :: MutableArrayArray# s
-> Int# -> MutableByteArray s -> State# s -> State# s
writeUnliftedArray# MutableArrayArray# s
a Int#
i (MutableByteArray MutableByteArray# s
x) =
MutableArrayArray# s
-> Int# -> MutableByteArray# s -> State# s -> State# s
forall d.
MutableArrayArray# d
-> Int# -> MutableByteArray# d -> State# d -> State# d
writeMutableByteArrayArray# MutableArrayArray# s
a Int#
i (MutableByteArray# s -> MutableByteArray# s
unsafeCoerce# MutableByteArray# s
x)
readUnliftedArray# :: MutableArrayArray# s
-> Int# -> State# s -> (# State# s, MutableByteArray s #)
readUnliftedArray# MutableArrayArray# s
a Int#
i State# s
s0 = case MutableArrayArray# s
-> Int# -> State# s -> (# State# s, MutableByteArray# s #)
forall d.
MutableArrayArray# d
-> Int# -> State# d -> (# State# d, MutableByteArray# d #)
readMutableByteArrayArray# MutableArrayArray# s
a Int#
i State# s
s0 of
(# State# s
s1, MutableByteArray# s
x #) -> (# State# s
s1, MutableByteArray# s -> MutableByteArray s
forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray (MutableByteArray# s -> MutableByteArray# s
unsafeCoerce# MutableByteArray# s
x) #)
indexUnliftedArray# :: ArrayArray# -> Int# -> MutableByteArray s
indexUnliftedArray# ArrayArray#
a Int#
i = MutableByteArray# s -> MutableByteArray s
forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray (ByteArray# -> MutableByteArray# s
unsafeCoerce# (ArrayArray# -> Int# -> ByteArray#
indexByteArrayArray# ArrayArray#
a Int#
i))
instance PrimUnlifted (MutablePrimArray s a) where
{-# inline writeUnliftedArray# #-}
{-# inline readUnliftedArray# #-}
{-# inline indexUnliftedArray# #-}
writeUnliftedArray# :: MutableArrayArray# s
-> Int# -> MutablePrimArray s a -> State# s -> State# s
writeUnliftedArray# MutableArrayArray# s
a Int#
i (MutablePrimArray MutableByteArray# s
x) =
MutableArrayArray# s
-> Int# -> MutableByteArray# s -> State# s -> State# s
forall d.
MutableArrayArray# d
-> Int# -> MutableByteArray# d -> State# d -> State# d
writeMutableByteArrayArray# MutableArrayArray# s
a Int#
i (MutableByteArray# s -> MutableByteArray# s
unsafeCoerce# MutableByteArray# s
x)
readUnliftedArray# :: MutableArrayArray# s
-> Int# -> State# s -> (# State# s, MutablePrimArray s a #)
readUnliftedArray# MutableArrayArray# s
a Int#
i State# s
s0 = case MutableArrayArray# s
-> Int# -> State# s -> (# State# s, MutableByteArray# s #)
forall d.
MutableArrayArray# d
-> Int# -> State# d -> (# State# d, MutableByteArray# d #)
readMutableByteArrayArray# MutableArrayArray# s
a Int#
i State# s
s0 of
(# State# s
s1, MutableByteArray# s
x #) -> (# State# s
s1, MutableByteArray# s -> MutablePrimArray s a
forall s a. MutableByteArray# s -> MutablePrimArray s a
MutablePrimArray (MutableByteArray# s -> MutableByteArray# s
unsafeCoerce# MutableByteArray# s
x) #)
indexUnliftedArray# :: ArrayArray# -> Int# -> MutablePrimArray s a
indexUnliftedArray# ArrayArray#
a Int#
i = MutableByteArray# s -> MutablePrimArray s a
forall s a. MutableByteArray# s -> MutablePrimArray s a
MutablePrimArray (ByteArray# -> MutableByteArray# s
unsafeCoerce# (ArrayArray# -> Int# -> ByteArray#
indexByteArrayArray# ArrayArray#
a Int#
i))
instance PrimUnlifted (MVar a) where
{-# inline writeUnliftedArray# #-}
{-# inline readUnliftedArray# #-}
{-# inline indexUnliftedArray# #-}
writeUnliftedArray# :: MutableArrayArray# s -> Int# -> MVar a -> State# s -> State# s
writeUnliftedArray# MutableArrayArray# s
a Int#
i (MVar MVar# RealWorld a
x) =
MutableArrayArray# s -> Int# -> ArrayArray# -> State# s -> State# s
forall d.
MutableArrayArray# d -> Int# -> ArrayArray# -> State# d -> State# d
writeArrayArrayArray# MutableArrayArray# s
a Int#
i (MVar# RealWorld a -> ArrayArray#
unsafeCoerce# MVar# RealWorld a
x)
readUnliftedArray# :: MutableArrayArray# s -> Int# -> State# s -> (# State# s, MVar a #)
readUnliftedArray# MutableArrayArray# s
a Int#
i State# s
s0 = case MutableArrayArray# s
-> Int# -> State# s -> (# State# s, ArrayArray# #)
forall d.
MutableArrayArray# d
-> Int# -> State# d -> (# State# d, ArrayArray# #)
readArrayArrayArray# MutableArrayArray# s
a Int#
i State# s
s0 of
(# State# s
s1, ArrayArray#
x #) -> (# State# s
s1, MVar# RealWorld a -> MVar a
forall a. MVar# RealWorld a -> MVar a
MVar (ArrayArray# -> MVar# RealWorld a
unsafeCoerce# ArrayArray#
x) #)
indexUnliftedArray# :: ArrayArray# -> Int# -> MVar a
indexUnliftedArray# ArrayArray#
a Int#
i = MVar# RealWorld a -> MVar a
forall a. MVar# RealWorld a -> MVar a
MVar (ArrayArray# -> MVar# RealWorld a
unsafeCoerce# (ArrayArray# -> Int# -> ArrayArray#
indexArrayArrayArray# ArrayArray#
a Int#
i))
instance PrimUnlifted (STRef s a) where
{-# inline writeUnliftedArray# #-}
{-# inline readUnliftedArray# #-}
{-# inline indexUnliftedArray# #-}
writeUnliftedArray# :: MutableArrayArray# s -> Int# -> STRef s a -> State# s -> State# s
writeUnliftedArray# MutableArrayArray# s
a Int#
i (STRef MutVar# s a
x) =
MutableArrayArray# s -> Int# -> ArrayArray# -> State# s -> State# s
forall d.
MutableArrayArray# d -> Int# -> ArrayArray# -> State# d -> State# d
writeArrayArrayArray# MutableArrayArray# s
a Int#
i (MutVar# s a -> ArrayArray#
unsafeCoerce# MutVar# s a
x)
readUnliftedArray# :: MutableArrayArray# s
-> Int# -> State# s -> (# State# s, STRef s a #)
readUnliftedArray# MutableArrayArray# s
a Int#
i State# s
s0 = case MutableArrayArray# s
-> Int# -> State# s -> (# State# s, ArrayArray# #)
forall d.
MutableArrayArray# d
-> Int# -> State# d -> (# State# d, ArrayArray# #)
readArrayArrayArray# MutableArrayArray# s
a Int#
i State# s
s0 of
(# State# s
s1, ArrayArray#
x #) -> (# State# s
s1, MutVar# s a -> STRef s a
forall s a. MutVar# s a -> STRef s a
STRef (ArrayArray# -> MutVar# s a
unsafeCoerce# ArrayArray#
x) #)
indexUnliftedArray# :: ArrayArray# -> Int# -> STRef s a
indexUnliftedArray# ArrayArray#
a Int#
i =
MutVar# s a -> STRef s a
forall s a. MutVar# s a -> STRef s a
STRef (ArrayArray# -> MutVar# s a
unsafeCoerce# (ArrayArray# -> Int# -> ArrayArray#
indexArrayArrayArray# ArrayArray#
a Int#
i))
instance PrimUnlifted (IORef a) where
{-# inline writeUnliftedArray# #-}
{-# inline readUnliftedArray# #-}
{-# inline indexUnliftedArray# #-}
writeUnliftedArray# :: MutableArrayArray# s -> Int# -> IORef a -> State# s -> State# s
writeUnliftedArray# MutableArrayArray# s
a Int#
i (IORef STRef RealWorld a
v) = MutableArrayArray# s
-> Int# -> STRef RealWorld a -> State# s -> State# s
forall a s.
PrimUnlifted a =>
MutableArrayArray# s -> Int# -> a -> State# s -> State# s
writeUnliftedArray# MutableArrayArray# s
a Int#
i STRef RealWorld a
v
readUnliftedArray# :: MutableArrayArray# s -> Int# -> State# s -> (# State# s, IORef a #)
readUnliftedArray# MutableArrayArray# s
a Int#
i State# s
s0 = case MutableArrayArray# s
-> Int# -> State# s -> (# State# s, STRef RealWorld a #)
forall a s.
PrimUnlifted a =>
MutableArrayArray# s -> Int# -> State# s -> (# State# s, a #)
readUnliftedArray# MutableArrayArray# s
a Int#
i State# s
s0 of
(# State# s
s1, STRef RealWorld a
v #) -> (# State# s
s1, STRef RealWorld a -> IORef a
forall a. STRef RealWorld a -> IORef a
IORef STRef RealWorld a
v #)
indexUnliftedArray# :: ArrayArray# -> Int# -> IORef a
indexUnliftedArray# ArrayArray#
a Int#
i = STRef RealWorld a -> IORef a
forall a. STRef RealWorld a -> IORef a
IORef (ArrayArray# -> Int# -> STRef RealWorld a
forall a. PrimUnlifted a => ArrayArray# -> Int# -> a
indexUnliftedArray# ArrayArray#
a Int#
i)
data MutableUnliftedArray s a
= MutableUnliftedArray (MutableArrayArray# s)
data UnliftedArray a
= UnliftedArray ArrayArray#
unsafeNewUnliftedArray
:: (PrimMonad m)
=> Int
-> m (MutableUnliftedArray (PrimState m) a)
{-# inline unsafeNewUnliftedArray #-}
unsafeNewUnliftedArray :: Int -> m (MutableUnliftedArray (PrimState m) a)
unsafeNewUnliftedArray (I# Int#
i#) = (State# (PrimState m)
-> (# State# (PrimState m),
MutableUnliftedArray (PrimState m) a #))
-> m (MutableUnliftedArray (PrimState m) a)
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive ((State# (PrimState m)
-> (# State# (PrimState m),
MutableUnliftedArray (PrimState m) a #))
-> m (MutableUnliftedArray (PrimState m) a))
-> (State# (PrimState m)
-> (# State# (PrimState m),
MutableUnliftedArray (PrimState m) a #))
-> m (MutableUnliftedArray (PrimState m) a)
forall a b. (a -> b) -> a -> b
$ \State# (PrimState m)
s -> case Int#
-> State# (PrimState m)
-> (# State# (PrimState m), MutableArrayArray# (PrimState m) #)
forall d. Int# -> State# d -> (# State# d, MutableArrayArray# d #)
newArrayArray# Int#
i# State# (PrimState m)
s of
(# State# (PrimState m)
s', MutableArrayArray# (PrimState m)
maa# #) -> (# State# (PrimState m)
s', MutableArrayArray# (PrimState m)
-> MutableUnliftedArray (PrimState m) a
forall k s (a :: k).
MutableArrayArray# s -> MutableUnliftedArray s a
MutableUnliftedArray MutableArrayArray# (PrimState m)
maa# #)
newUnliftedArray
:: (PrimMonad m, PrimUnlifted a)
=> Int
-> a
-> m (MutableUnliftedArray (PrimState m) a)
newUnliftedArray :: Int -> a -> m (MutableUnliftedArray (PrimState m) a)
newUnliftedArray Int
len a
v = do
MutableUnliftedArray (PrimState m) a
mua <- Int -> m (MutableUnliftedArray (PrimState m) a)
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
Int -> m (MutableUnliftedArray (PrimState m) a)
unsafeNewUnliftedArray Int
len
MutableUnliftedArray (PrimState m) a -> Int -> Int -> a -> m ()
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> Int -> a -> m ()
setUnliftedArray MutableUnliftedArray (PrimState m) a
mua Int
0 Int
len a
v
MutableUnliftedArray (PrimState m) a
-> m (MutableUnliftedArray (PrimState m) a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MutableUnliftedArray (PrimState m) a
mua
{-# inline newUnliftedArray #-}
setUnliftedArray
:: (PrimMonad m, PrimUnlifted a)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> a
-> m ()
{-# inline setUnliftedArray #-}
setUnliftedArray :: MutableUnliftedArray (PrimState m) a -> Int -> Int -> a -> m ()
setUnliftedArray MutableUnliftedArray (PrimState m) a
mua Int
off Int
len a
v = Int -> m ()
loop (Int
len Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
where
loop :: Int -> m ()
loop Int
i
| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
off = () -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
| Bool
otherwise = MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray MutableUnliftedArray (PrimState m) a
mua Int
i a
v m () -> m () -> m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
loop (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)
sizeofUnliftedArray :: UnliftedArray e -> Int
{-# inline sizeofUnliftedArray #-}
sizeofUnliftedArray :: UnliftedArray e -> Int
sizeofUnliftedArray (UnliftedArray ArrayArray#
aa#) = Int# -> Int
I# (ArrayArray# -> Int#
sizeofArrayArray# ArrayArray#
aa#)
sizeofMutableUnliftedArray :: MutableUnliftedArray s e -> Int
{-# inline sizeofMutableUnliftedArray #-}
sizeofMutableUnliftedArray :: MutableUnliftedArray s e -> Int
sizeofMutableUnliftedArray (MutableUnliftedArray MutableArrayArray# s
maa#)
= Int# -> Int
I# (MutableArrayArray# s -> Int#
forall d. MutableArrayArray# d -> Int#
sizeofMutableArrayArray# MutableArrayArray# s
maa#)
writeUnliftedArray :: (PrimMonad m, PrimUnlifted a)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> a
-> m ()
{-# inline writeUnliftedArray #-}
writeUnliftedArray :: MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray (MutableUnliftedArray MutableArrayArray# (PrimState m)
arr) (I# Int#
ix) a
a =
(State# (PrimState m) -> State# (PrimState m)) -> m ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableArrayArray# (PrimState m)
-> Int# -> a -> State# (PrimState m) -> State# (PrimState m)
forall a s.
PrimUnlifted a =>
MutableArrayArray# s -> Int# -> a -> State# s -> State# s
writeUnliftedArray# MutableArrayArray# (PrimState m)
arr Int#
ix a
a)
readUnliftedArray :: (PrimMonad m, PrimUnlifted a)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> m a
{-# inline readUnliftedArray #-}
readUnliftedArray :: MutableUnliftedArray (PrimState m) a -> Int -> m a
readUnliftedArray (MutableUnliftedArray MutableArrayArray# (PrimState m)
arr) (I# Int#
ix) =
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive (MutableArrayArray# (PrimState m)
-> Int# -> State# (PrimState m) -> (# State# (PrimState m), a #)
forall a s.
PrimUnlifted a =>
MutableArrayArray# s -> Int# -> State# s -> (# State# s, a #)
readUnliftedArray# MutableArrayArray# (PrimState m)
arr Int#
ix)
indexUnliftedArray :: PrimUnlifted a
=> UnliftedArray a
-> Int
-> a
{-# inline indexUnliftedArray #-}
indexUnliftedArray :: UnliftedArray a -> Int -> a
indexUnliftedArray (UnliftedArray ArrayArray#
arr) (I# Int#
ix) =
ArrayArray# -> Int# -> a
forall a. PrimUnlifted a => ArrayArray# -> Int# -> a
indexUnliftedArray# ArrayArray#
arr Int#
ix
unsafeFreezeUnliftedArray
:: (PrimMonad m)
=> MutableUnliftedArray (PrimState m) a
-> m (UnliftedArray a)
unsafeFreezeUnliftedArray :: MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
unsafeFreezeUnliftedArray (MutableUnliftedArray MutableArrayArray# (PrimState m)
maa#)
= (State# (PrimState m)
-> (# State# (PrimState m), UnliftedArray a #))
-> m (UnliftedArray a)
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive ((State# (PrimState m)
-> (# State# (PrimState m), UnliftedArray a #))
-> m (UnliftedArray a))
-> (State# (PrimState m)
-> (# State# (PrimState m), UnliftedArray a #))
-> m (UnliftedArray a)
forall a b. (a -> b) -> a -> b
$ \State# (PrimState m)
s -> case MutableArrayArray# (PrimState m)
-> State# (PrimState m) -> (# State# (PrimState m), ArrayArray# #)
forall d.
MutableArrayArray# d -> State# d -> (# State# d, ArrayArray# #)
unsafeFreezeArrayArray# MutableArrayArray# (PrimState m)
maa# State# (PrimState m)
s of
(# State# (PrimState m)
s', ArrayArray#
aa# #) -> (# State# (PrimState m)
s', ArrayArray# -> UnliftedArray a
forall k (a :: k). ArrayArray# -> UnliftedArray a
UnliftedArray ArrayArray#
aa# #)
{-# inline unsafeFreezeUnliftedArray #-}
sameMutableUnliftedArray
:: MutableUnliftedArray s a
-> MutableUnliftedArray s a
-> Bool
sameMutableUnliftedArray :: MutableUnliftedArray s a -> MutableUnliftedArray s a -> Bool
sameMutableUnliftedArray (MutableUnliftedArray MutableArrayArray# s
maa1#) (MutableUnliftedArray MutableArrayArray# s
maa2#)
= Int# -> Bool
isTrue# (MutableArrayArray# s -> MutableArrayArray# s -> Int#
forall d. MutableArrayArray# d -> MutableArrayArray# d -> Int#
sameMutableArrayArray# MutableArrayArray# s
maa1# MutableArrayArray# s
maa2#)
{-# inline sameMutableUnliftedArray #-}
copyUnliftedArray
:: (PrimMonad m)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> UnliftedArray a
-> Int
-> Int
-> m ()
{-# inline copyUnliftedArray #-}
copyUnliftedArray :: MutableUnliftedArray (PrimState m) a
-> Int -> UnliftedArray a -> Int -> Int -> m ()
copyUnliftedArray
(MutableUnliftedArray MutableArrayArray# (PrimState m)
dst) (I# Int#
doff)
(UnliftedArray ArrayArray#
src) (I# Int#
soff) (I# Int#
ln) =
(State# (PrimState m) -> State# (PrimState m)) -> m ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ ((State# (PrimState m) -> State# (PrimState m)) -> m ())
-> (State# (PrimState m) -> State# (PrimState m)) -> m ()
forall a b. (a -> b) -> a -> b
$ ArrayArray#
-> Int#
-> MutableArrayArray# (PrimState m)
-> Int#
-> Int#
-> State# (PrimState m)
-> State# (PrimState m)
forall d.
ArrayArray#
-> Int#
-> MutableArrayArray# d
-> Int#
-> Int#
-> State# d
-> State# d
copyArrayArray# ArrayArray#
src Int#
soff MutableArrayArray# (PrimState m)
dst Int#
doff Int#
ln
copyMutableUnliftedArray
:: (PrimMonad m)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m ()
{-# inline copyMutableUnliftedArray #-}
copyMutableUnliftedArray :: MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m ()
copyMutableUnliftedArray
(MutableUnliftedArray MutableArrayArray# (PrimState m)
dst) (I# Int#
doff)
(MutableUnliftedArray MutableArrayArray# (PrimState m)
src) (I# Int#
soff) (I# Int#
ln) =
(State# (PrimState m) -> State# (PrimState m)) -> m ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ ((State# (PrimState m) -> State# (PrimState m)) -> m ())
-> (State# (PrimState m) -> State# (PrimState m)) -> m ()
forall a b. (a -> b) -> a -> b
$ MutableArrayArray# (PrimState m)
-> Int#
-> MutableArrayArray# (PrimState m)
-> Int#
-> Int#
-> State# (PrimState m)
-> State# (PrimState m)
forall d.
MutableArrayArray# d
-> Int#
-> MutableArrayArray# d
-> Int#
-> Int#
-> State# d
-> State# d
copyMutableArrayArray# MutableArrayArray# (PrimState m)
src Int#
soff MutableArrayArray# (PrimState m)
dst Int#
doff Int#
ln
freezeUnliftedArray
:: (PrimMonad m)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m (UnliftedArray a)
freezeUnliftedArray :: MutableUnliftedArray (PrimState m) a
-> Int -> Int -> m (UnliftedArray a)
freezeUnliftedArray MutableUnliftedArray (PrimState m) a
src Int
off Int
len = do
MutableUnliftedArray (PrimState m) a
dst <- Int -> m (MutableUnliftedArray (PrimState m) a)
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
Int -> m (MutableUnliftedArray (PrimState m) a)
unsafeNewUnliftedArray Int
len
MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m ()
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m ()
copyMutableUnliftedArray MutableUnliftedArray (PrimState m) a
dst Int
0 MutableUnliftedArray (PrimState m) a
src Int
off Int
len
MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
unsafeFreezeUnliftedArray MutableUnliftedArray (PrimState m) a
dst
{-# inline freezeUnliftedArray #-}
thawUnliftedArray
:: (PrimMonad m)
=> UnliftedArray a
-> Int
-> Int
-> m (MutableUnliftedArray (PrimState m) a)
{-# inline thawUnliftedArray #-}
thawUnliftedArray :: UnliftedArray a
-> Int -> Int -> m (MutableUnliftedArray (PrimState m) a)
thawUnliftedArray UnliftedArray a
src Int
off Int
len = do
MutableUnliftedArray (PrimState m) a
dst <- Int -> m (MutableUnliftedArray (PrimState m) a)
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
Int -> m (MutableUnliftedArray (PrimState m) a)
unsafeNewUnliftedArray Int
len
MutableUnliftedArray (PrimState m) a
-> Int -> UnliftedArray a -> Int -> Int -> m ()
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int -> UnliftedArray a -> Int -> Int -> m ()
copyUnliftedArray MutableUnliftedArray (PrimState m) a
dst Int
0 UnliftedArray a
src Int
off Int
len
MutableUnliftedArray (PrimState m) a
-> m (MutableUnliftedArray (PrimState m) a)
forall (m :: * -> *) a. Monad m => a -> m a
return MutableUnliftedArray (PrimState m) a
dst
cloneUnliftedArray
:: UnliftedArray a
-> Int
-> Int
-> UnliftedArray a
{-# inline cloneUnliftedArray #-}
cloneUnliftedArray :: UnliftedArray a -> Int -> Int -> UnliftedArray a
cloneUnliftedArray UnliftedArray a
src Int
off Int
len = IO (UnliftedArray a) -> UnliftedArray a
forall a. IO a -> a
unsafeDupablePerformIO (IO (UnliftedArray a) -> UnliftedArray a)
-> IO (UnliftedArray a) -> UnliftedArray a
forall a b. (a -> b) -> a -> b
$ do
MutableUnliftedArray RealWorld a
dst <- Int -> IO (MutableUnliftedArray (PrimState IO) a)
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
Int -> m (MutableUnliftedArray (PrimState m) a)
unsafeNewUnliftedArray Int
len
MutableUnliftedArray (PrimState IO) a
-> Int -> UnliftedArray a -> Int -> Int -> IO ()
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int -> UnliftedArray a -> Int -> Int -> m ()
copyUnliftedArray MutableUnliftedArray RealWorld a
MutableUnliftedArray (PrimState IO) a
dst Int
0 UnliftedArray a
src Int
off Int
len
MutableUnliftedArray (PrimState IO) a -> IO (UnliftedArray a)
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
unsafeFreezeUnliftedArray MutableUnliftedArray RealWorld a
MutableUnliftedArray (PrimState IO) a
dst
cloneMutableUnliftedArray
:: (PrimMonad m)
=> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m (MutableUnliftedArray (PrimState m) a)
{-# inline cloneMutableUnliftedArray #-}
cloneMutableUnliftedArray :: MutableUnliftedArray (PrimState m) a
-> Int -> Int -> m (MutableUnliftedArray (PrimState m) a)
cloneMutableUnliftedArray MutableUnliftedArray (PrimState m) a
src Int
off Int
len = do
MutableUnliftedArray (PrimState m) a
dst <- Int -> m (MutableUnliftedArray (PrimState m) a)
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
Int -> m (MutableUnliftedArray (PrimState m) a)
unsafeNewUnliftedArray Int
len
MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m ()
forall k (m :: * -> *) (a :: k).
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m ()
copyMutableUnliftedArray MutableUnliftedArray (PrimState m) a
dst Int
0 MutableUnliftedArray (PrimState m) a
src Int
off Int
len
MutableUnliftedArray (PrimState m) a
-> m (MutableUnliftedArray (PrimState m) a)
forall (m :: * -> *) a. Monad m => a -> m a
return MutableUnliftedArray (PrimState m) a
dst