{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedNewtypes #-}
module Data.Primitive.Contiguous.Class
( Contiguous(..)
, Slice(..)
, MutableSlice(..)
, ContiguousU(..)
, Always
) where
import Data.Primitive.Contiguous.Shim
import Data.Primitive hiding (fromList,fromListN)
import Data.Primitive.Unlifted.Array
import Prelude hiding (length,map,all,any,foldr,foldMap,traverse,read,filter,replicate,null,reverse,foldl,foldr,zip,zipWith,scanl,(<$),elem,maximum,minimum,mapM,mapM_,sequence,sequence_)
import Control.DeepSeq (NFData)
import Control.Monad.Primitive (PrimState, PrimMonad(..))
import Control.Monad.ST (runST,ST)
import Control.Monad.ST.Run (runPrimArrayST,runSmallArrayST,runUnliftedArrayST,runArrayST)
import Data.Kind (Type)
import Data.Primitive.Unlifted.Class (PrimUnlifted)
import GHC.Exts (ArrayArray#,Constraint,sizeofByteArray#,sizeofArray#,sizeofArrayArray#)
import GHC.Exts (SmallMutableArray#,MutableArray#,MutableArrayArray#)
import GHC.Exts (SmallArray#,Array#)
import GHC.Exts (TYPE,RuntimeRep(UnliftedRep))
import qualified Control.DeepSeq as DS
data Slice arr a = Slice
{ Slice arr a -> Int
offset :: {-# UNPACK #-} !Int
, Slice arr a -> Int
length :: {-# UNPACK #-} !Int
, Slice arr a -> Unlifted arr a
base :: !(Unlifted arr a)
}
data MutableSlice arr s a = MutableSlice
{ MutableSlice arr s a -> Int
offsetMut :: {-# UNPACK #-} !Int
, MutableSlice arr s a -> Int
lengthMut :: {-# UNPACK #-} !Int
, MutableSlice arr s a -> UnliftedMut arr s a
baseMut :: !(UnliftedMut arr s a)
}
class Contiguous (arr :: Type -> Type) where
type family Mutable arr = (r :: Type -> Type -> Type) | r -> arr
type family Element arr :: Type -> Constraint
type family Sliced arr :: Type -> Type
type family MutableSliced arr :: Type -> Type -> Type
new :: (PrimMonad m, Element arr b) => Int -> m (Mutable arr (PrimState m) b)
replicateMut :: (PrimMonad m, Element arr b)
=> Int
-> b
-> m (Mutable arr (PrimState m) b)
shrink :: (PrimMonad m, Element arr a)
=> Mutable arr (PrimState m) a
-> Int
-> m (Mutable arr (PrimState m) a)
default shrink ::
( ContiguousU arr
, PrimMonad m, Element arr a)
=> Mutable arr (PrimState m) a -> Int -> m (Mutable arr (PrimState m) a)
{-# INLINE shrink #-}
shrink = Mutable arr (PrimState m) a
-> Int -> m (Mutable arr (PrimState m) a)
forall (arr :: * -> *) (m :: * -> *) b.
(ContiguousU arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b
-> Int -> m (Mutable arr (PrimState m) b)
resize
empty :: arr a
singleton :: Element arr a => a -> arr a
doubleton :: Element arr a => a -> a -> arr a
tripleton :: Element arr a => a -> a -> a -> arr a
quadrupleton :: Element arr a => a -> a -> a -> a -> arr a
index :: Element arr b => arr b -> Int -> b
index# :: Element arr b => arr b -> Int -> (# b #)
indexM :: (Element arr b, Monad m) => arr b -> Int -> m b
read :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b -> Int -> m b
write :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b -> Int -> b -> m ()
null :: arr b -> Bool
size :: Element arr b => arr b -> Int
sizeMut :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b -> m Int
equals :: (Element arr b, Eq b) => arr b -> arr b -> Bool
equalsMut :: Mutable arr s a -> Mutable arr s a -> Bool
slice :: (Element arr a)
=> arr a
-> Int
-> Int
-> Sliced arr a
sliceMut :: (Element arr a)
=> Mutable arr s a
-> Int
-> Int
-> MutableSliced arr s a
toSlice :: (Element arr a) => arr a -> Sliced arr a
toSliceMut :: (PrimMonad m, Element arr a)
=> Mutable arr (PrimState m) a
-> m (MutableSliced arr (PrimState m) a)
clone :: Element arr b
=> Sliced arr b
-> arr b
default clone ::
( Sliced arr ~ Slice arr, ContiguousU arr
, Element arr b)
=> Sliced arr b -> arr b
{-# INLINE clone #-}
clone Slice{offset,length,base} = arr b -> Int -> Int -> arr b
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
arr a -> Int -> Int -> arr a
clone_ (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) Int
offset Int
length
clone_ :: Element arr a => arr a -> Int -> Int -> arr a
cloneMut :: (PrimMonad m, Element arr b)
=> MutableSliced arr (PrimState m) b
-> m (Mutable arr (PrimState m) b)
default cloneMut ::
( MutableSliced arr ~ MutableSlice arr, ContiguousU arr
, PrimMonad m, Element arr b)
=> MutableSliced arr (PrimState m) b -> m (Mutable arr (PrimState m) b)
{-# INLINE cloneMut #-}
cloneMut MutableSlice{offsetMut,lengthMut,baseMut}
= Mutable arr (PrimState m) b
-> Int -> Int -> m (Mutable arr (PrimState m) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b
-> Int -> Int -> m (Mutable arr (PrimState m) b)
cloneMut_ (UnliftedMut arr (PrimState m) b -> Mutable arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) b
baseMut) Int
offsetMut Int
lengthMut
cloneMut_ :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b
-> Int
-> Int
-> m (Mutable arr (PrimState m) b)
freeze :: (PrimMonad m, Element arr a)
=> MutableSliced arr (PrimState m) a
-> m (arr a)
default freeze ::
( MutableSliced arr ~ MutableSlice arr, ContiguousU arr
, PrimMonad m, Element arr a)
=> MutableSliced arr (PrimState m) a -> m (arr a)
{-# INLINE freeze #-}
freeze MutableSlice{offsetMut,lengthMut,baseMut}
= Mutable arr (PrimState m) a -> Int -> Int -> m (arr a)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)
freeze_ (UnliftedMut arr (PrimState m) a -> Mutable arr (PrimState m) a
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) a
baseMut) Int
offsetMut Int
lengthMut
freeze_ :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b
-> Int
-> Int
-> m (arr b)
unsafeFreeze :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b
-> m (arr b)
unsafeFreeze Mutable arr (PrimState m) b
xs = Mutable arr (PrimState m) b -> Int -> m (arr b)
forall (arr :: * -> *) (m :: * -> *) a.
(Contiguous arr, PrimMonad m, Element arr a) =>
Mutable arr (PrimState m) a -> Int -> m (arr a)
unsafeShrinkAndFreeze Mutable arr (PrimState m) b
xs (Int -> m (arr b)) -> m Int -> m (arr b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Mutable arr (PrimState m) b -> m Int
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m Int
sizeMut Mutable arr (PrimState m) b
xs
{-# INLINE unsafeFreeze #-}
unsafeShrinkAndFreeze :: (PrimMonad m, Element arr a)
=> Mutable arr (PrimState m) a
-> Int
-> m (arr a)
default unsafeShrinkAndFreeze ::
( ContiguousU arr
, PrimMonad m, Element arr a)
=> Mutable arr (PrimState m) a -> Int -> m (arr a)
{-# INLINE unsafeShrinkAndFreeze #-}
unsafeShrinkAndFreeze Mutable arr (PrimState m) a
arr0 Int
len' =
Mutable arr (PrimState m) a
-> Int -> m (Mutable arr (PrimState m) a)
forall (arr :: * -> *) (m :: * -> *) b.
(ContiguousU arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b
-> Int -> m (Mutable arr (PrimState m) b)
resize Mutable arr (PrimState m) a
arr0 Int
len' m (Mutable arr (PrimState m) a)
-> (Mutable arr (PrimState m) a -> m (arr a)) -> m (arr a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Mutable arr (PrimState m) a -> m (arr a)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m (arr b)
unsafeFreeze
thaw :: (PrimMonad m, Element arr b)
=> Sliced arr b
-> m (Mutable arr (PrimState m) b)
default thaw ::
( Sliced arr ~ Slice arr, ContiguousU arr
, PrimMonad m, Element arr b)
=> Sliced arr b
-> m (Mutable arr (PrimState m) b)
{-# INLINE thaw #-}
thaw Slice{offset,length,base} = arr b -> Int -> Int -> m (Mutable arr (PrimState m) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
arr b -> Int -> Int -> m (Mutable arr (PrimState m) b)
thaw_ (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) Int
offset Int
length
thaw_ :: (PrimMonad m, Element arr b)
=> arr b
-> Int
-> Int
-> m (Mutable arr (PrimState m) b)
copy :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b
-> Int
-> Sliced arr b
-> m ()
default copy ::
( Sliced arr ~ Slice arr, ContiguousU arr
, PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b -> Int -> Sliced arr b -> m ()
{-# INLINE copy #-}
copy Mutable arr (PrimState m) b
dst Int
dstOff Slice{offset,length,base} = Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()
copy_ Mutable arr (PrimState m) b
dst Int
dstOff (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) Int
offset Int
length
copy_ :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b
-> Int
-> arr b
-> Int
-> Int
-> m ()
copyMut :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b
-> Int
-> MutableSliced arr (PrimState m) b
-> m ()
default copyMut ::
( MutableSliced arr ~ MutableSlice arr, ContiguousU arr
, PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b -> Int -> MutableSliced arr (PrimState m) b -> m ()
{-# INLINE copyMut #-}
copyMut Mutable arr (PrimState m) b
dst Int
dstOff MutableSlice{offsetMut,lengthMut,baseMut}
= Mutable arr (PrimState m) b
-> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b
-> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m ()
copyMut_ Mutable arr (PrimState m) b
dst Int
dstOff (UnliftedMut arr (PrimState m) b -> Mutable arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) b
baseMut) Int
offsetMut Int
lengthMut
copyMut_ :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b
-> Int
-> Mutable arr (PrimState m) b
-> Int
-> Int
-> m ()
insertAt :: (Element arr b)
=> arr b
-> Int
-> b
-> arr b
default insertAt ::
(Element arr b, ContiguousU arr)
=> arr b -> Int -> b -> arr b
insertAt arr b
src Int
i b
x = (forall s. ST s (arr b)) -> arr b
forall (arr :: * -> *) a.
Contiguous arr =>
(forall s. ST s (arr a)) -> arr a
run ((forall s. ST s (arr b)) -> arr b)
-> (forall s. ST s (arr b)) -> arr b
forall a b. (a -> b) -> a -> b
$ do
Mutable arr s b
dst <- Int -> b -> ST s (Mutable arr (PrimState (ST s)) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Int -> b -> m (Mutable arr (PrimState m) b)
replicateMut (arr b -> Int
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int
size arr b
src Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) b
x
Mutable arr (PrimState (ST s)) b -> Int -> Sliced arr b -> ST s ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> Sliced arr b -> m ()
copy Mutable arr s b
Mutable arr (PrimState (ST s)) b
dst Int
0 (arr b -> Int -> Int -> Sliced arr b
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
arr a -> Int -> Int -> Sliced arr a
slice arr b
src Int
0 Int
i)
Mutable arr (PrimState (ST s)) b -> Int -> Sliced arr b -> ST s ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> Sliced arr b -> m ()
copy Mutable arr s b
Mutable arr (PrimState (ST s)) b
dst (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (arr b -> Int -> Int -> Sliced arr b
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
arr a -> Int -> Int -> Sliced arr a
slice arr b
src Int
i (arr b -> Int
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int
size arr b
src Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i))
Mutable arr (PrimState (ST s)) b -> ST s (arr b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m (arr b)
unsafeFreeze Mutable arr s b
Mutable arr (PrimState (ST s)) b
dst
{-# inline insertAt #-}
rnf :: (NFData a, Element arr a) => arr a -> ()
run :: (forall s. ST s (arr a)) -> arr a
class (Contiguous arr) => ContiguousU arr where
type Unlifted arr = (r :: Type -> TYPE 'UnliftedRep) | r -> arr
type UnliftedMut arr = (r :: Type -> Type -> TYPE 'UnliftedRep) | r -> arr
resize :: (PrimMonad m, Element arr b)
=> Mutable arr (PrimState m) b
-> Int
-> m (Mutable arr (PrimState m) b)
unlift :: arr b -> Unlifted arr b
unliftMut :: Mutable arr s b -> UnliftedMut arr s b
lift :: Unlifted arr b -> arr b
liftMut :: UnliftedMut arr s b -> Mutable arr s b
class Always a where {}
instance Always a where {}
instance (ContiguousU arr) => Contiguous (Slice arr) where
type Mutable (Slice arr) = MutableSlice arr
type Element (Slice arr) = Element arr
type Sliced (Slice arr) = Slice arr
type MutableSliced (Slice arr) = MutableSlice arr
{-# INLINE new #-}
new :: Int -> m (Mutable (Slice arr) (PrimState m) b)
new Int
len = do
Mutable arr (PrimState m) b
baseMut <- Int -> m (Mutable arr (PrimState m) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Int -> m (Mutable arr (PrimState m) b)
new Int
len
MutableSlice arr (PrimState m) b
-> m (MutableSlice arr (PrimState m) b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{offsetMut :: Int
offsetMut=Int
0,lengthMut :: Int
lengthMut=Int
len,baseMut :: UnliftedMut arr (PrimState m) b
baseMut=Mutable arr (PrimState m) b -> UnliftedMut arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable arr (PrimState m) b
baseMut}
{-# INLINE replicateMut #-}
replicateMut :: Int -> b -> m (Mutable (Slice arr) (PrimState m) b)
replicateMut Int
len b
x = do
Mutable arr (PrimState m) b
baseMut <- Int -> b -> m (Mutable arr (PrimState m) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Int -> b -> m (Mutable arr (PrimState m) b)
replicateMut Int
len b
x
MutableSlice arr (PrimState m) b
-> m (MutableSlice arr (PrimState m) b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{offsetMut :: Int
offsetMut=Int
0,lengthMut :: Int
lengthMut=Int
len,baseMut :: UnliftedMut arr (PrimState m) b
baseMut=Mutable arr (PrimState m) b -> UnliftedMut arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable arr (PrimState m) b
baseMut}
{-# INLINE shrink #-}
shrink :: Mutable (Slice arr) (PrimState m) a
-> Int -> m (Mutable (Slice arr) (PrimState m) a)
shrink Mutable (Slice arr) (PrimState m) a
xs Int
len' = MutableSlice arr (PrimState m) a
-> m (MutableSlice arr (PrimState m) a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MutableSlice arr (PrimState m) a
-> m (MutableSlice arr (PrimState m) a))
-> MutableSlice arr (PrimState m) a
-> m (MutableSlice arr (PrimState m) a)
forall a b. (a -> b) -> a -> b
$ case Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
len' (MutableSlice arr (PrimState m) a -> Int
forall (arr :: * -> *) s a. MutableSlice arr s a -> Int
lengthMut Mutable (Slice arr) (PrimState m) a
MutableSlice arr (PrimState m) a
xs) of
Ordering
LT -> Mutable (Slice arr) (PrimState m) a
MutableSlice arr (PrimState m) a
xs{lengthMut :: Int
lengthMut=Int
len'}
Ordering
EQ -> Mutable (Slice arr) (PrimState m) a
MutableSlice arr (PrimState m) a
xs
Ordering
GT -> [Char] -> MutableSlice arr (PrimState m) a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"Data.Primitive.Contiguous.Class.shrink: passed a larger than existing size"
{-# INLINE empty #-}
empty :: Slice arr a
empty = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Int
0,base :: Unlifted arr a
base=arr a -> Unlifted arr a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift arr a
forall (arr :: * -> *) a. Contiguous arr => arr a
empty}
{-# INLINE singleton #-}
singleton :: a -> Slice arr a
singleton a
a = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Int
1,base :: Unlifted arr a
base=arr a -> Unlifted arr a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift (arr a -> Unlifted arr a) -> arr a -> Unlifted arr a
forall a b. (a -> b) -> a -> b
$ a -> arr a
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
a -> arr a
singleton a
a}
{-# INLINE doubleton #-}
doubleton :: a -> a -> Slice arr a
doubleton a
a a
b = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Int
2,base :: Unlifted arr a
base=arr a -> Unlifted arr a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift (arr a -> Unlifted arr a) -> arr a -> Unlifted arr a
forall a b. (a -> b) -> a -> b
$ a -> a -> arr a
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
a -> a -> arr a
doubleton a
a a
b}
{-# INLINE tripleton #-}
tripleton :: a -> a -> a -> Slice arr a
tripleton a
a a
b a
c = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Int
3,base :: Unlifted arr a
base=arr a -> Unlifted arr a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift (arr a -> Unlifted arr a) -> arr a -> Unlifted arr a
forall a b. (a -> b) -> a -> b
$ a -> a -> a -> arr a
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
a -> a -> a -> arr a
tripleton a
a a
b a
c}
{-# INLINE quadrupleton #-}
quadrupleton :: a -> a -> a -> a -> Slice arr a
quadrupleton a
a a
b a
c a
d = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Int
4,base :: Unlifted arr a
base=arr a -> Unlifted arr a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift (arr a -> Unlifted arr a) -> arr a -> Unlifted arr a
forall a b. (a -> b) -> a -> b
$ a -> a -> a -> a -> arr a
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
a -> a -> a -> a -> arr a
quadrupleton a
a a
b a
c a
d}
{-# INLINE index #-}
index :: Slice arr b -> Int -> b
index Slice{Int
offset :: Int
offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset,Unlifted arr b
base :: Unlifted arr b
base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base} Int
i = arr b -> Int -> b
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int -> b
index (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) (Int
offset Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i)
{-# INLINE index# #-}
index# :: Slice arr b -> Int -> (# b #)
index# Slice{Int
offset :: Int
offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset,Unlifted arr b
base :: Unlifted arr b
base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base} Int
i = arr b -> Int -> (# b #)
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int -> (# b #)
index# (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) (Int
offset Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i)
{-# INLINE indexM #-}
indexM :: Slice arr b -> Int -> m b
indexM Slice{Int
offset :: Int
offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset,Unlifted arr b
base :: Unlifted arr b
base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base} Int
i = arr b -> Int -> m b
forall (arr :: * -> *) b (m :: * -> *).
(Contiguous arr, Element arr b, Monad m) =>
arr b -> Int -> m b
indexM (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) (Int
offset Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i)
{-# INLINE read #-}
read :: Mutable (Slice arr) (PrimState m) b -> Int -> m b
read MutableSlice{offsetMut,baseMut} Int
i = Mutable arr (PrimState m) b -> Int -> m b
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> m b
read (UnliftedMut arr (PrimState m) b -> Mutable arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) b
baseMut) (Int
offsetMut Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i)
{-# INLINE write #-}
write :: Mutable (Slice arr) (PrimState m) b -> Int -> b -> m ()
write MutableSlice{offsetMut,baseMut} Int
i = Mutable arr (PrimState m) b -> Int -> b -> m ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> b -> m ()
write (UnliftedMut arr (PrimState m) b -> Mutable arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) b
baseMut) (Int
offsetMut Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i)
{-# INLINE null #-}
null :: Slice arr b -> Bool
null Slice{Int
length :: Int
length :: forall (arr :: * -> *) a. Slice arr a -> Int
length} = Int
length Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
{-# INLINE size #-}
size :: Slice arr b -> Int
size Slice{Int
length :: Int
length :: forall (arr :: * -> *) a. Slice arr a -> Int
length} = Int
length
{-# INLINE sizeMut #-}
sizeMut :: Mutable (Slice arr) (PrimState m) b -> m Int
sizeMut MutableSlice{lengthMut} = Int -> m Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
lengthMut
{-# INLINE equals #-}
equals :: Slice arr b -> Slice arr b -> Bool
equals Slice{offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset=Int
oA,length :: forall (arr :: * -> *) a. Slice arr a -> Int
length=Int
lenA,base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base=Unlifted arr b
a}
Slice{offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset=Int
oB,length :: forall (arr :: * -> *) a. Slice arr a -> Int
length=Int
lenB,base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base=Unlifted arr b
b}
= Int
lenA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
lenB Bool -> Bool -> Bool
&& Int -> Int -> Int -> Bool
loop Int
0 Int
oA Int
oB
where
loop :: Int -> Int -> Int -> Bool
loop !Int
i !Int
iA !Int
iB =
if Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
lenA then Bool
True
else arr b -> Int -> b
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int -> b
index (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
a) Int
iA b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== arr b -> Int -> b
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int -> b
index (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
b) Int
iB Bool -> Bool -> Bool
&& Int -> Int -> Int -> Bool
loop (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) (Int
iAInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) (Int
iBInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
{-# INLINE equalsMut #-}
equalsMut :: Mutable (Slice arr) s a -> Mutable (Slice arr) s a -> Bool
equalsMut MutableSlice{offsetMut=offA,lengthMut=lenA,baseMut=a}
MutableSlice{offsetMut=offB,lengthMut=lenB,baseMut=b}
= UnliftedMut arr s a -> Mutable arr s a
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr s a
a Mutable arr s a -> Mutable arr s a -> Bool
forall (arr :: * -> *) s a.
Contiguous arr =>
Mutable arr s a -> Mutable arr s a -> Bool
`equalsMut` UnliftedMut arr s a -> Mutable arr s a
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr s a
b
Bool -> Bool -> Bool
&& Int
offA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
offB
Bool -> Bool -> Bool
&& Int
lenA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
lenB
{-# INLINE slice #-}
slice :: Slice arr a -> Int -> Int -> Sliced (Slice arr) a
slice Slice{Int
offset :: Int
offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset,Unlifted arr a
base :: Unlifted arr a
base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base} Int
off' Int
len' = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice
{ offset :: Int
offset = Int
offset Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
off'
, length :: Int
length = Int
len'
, Unlifted arr a
base :: Unlifted arr a
base :: Unlifted arr a
base
}
{-# INLINE sliceMut #-}
sliceMut :: Mutable (Slice arr) s a
-> Int -> Int -> MutableSliced (Slice arr) s a
sliceMut MutableSlice{offsetMut,baseMut} Int
off' Int
len' = MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice
{ offsetMut :: Int
offsetMut = Int
offsetMut Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
off'
, lengthMut :: Int
lengthMut = Int
len'
, UnliftedMut arr s a
baseMut :: UnliftedMut arr s a
baseMut :: UnliftedMut arr s a
baseMut
}
{-# INLINE clone #-}
clone :: Sliced (Slice arr) b -> Slice arr b
clone = Sliced (Slice arr) b -> Slice arr b
forall a. a -> a
id
{-# INLINE clone_ #-}
clone_ :: Slice arr a -> Int -> Int -> Slice arr a
clone_ Slice{Int
offset :: Int
offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset,Unlifted arr a
base :: Unlifted arr a
base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base} Int
off' Int
len' =
Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
offsetInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
off',length :: Int
length=Int
len',Unlifted arr a
base :: Unlifted arr a
base :: Unlifted arr a
base}
{-# INLINE cloneMut #-}
cloneMut :: MutableSliced (Slice arr) (PrimState m) b
-> m (Mutable (Slice arr) (PrimState m) b)
cloneMut xs :: MutableSliced (Slice arr) (PrimState m) b
xs@MutableSlice{lengthMut} = Mutable (Slice arr) (PrimState m) b
-> Int -> Int -> m (Mutable (Slice arr) (PrimState m) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b
-> Int -> Int -> m (Mutable arr (PrimState m) b)
cloneMut_ Mutable (Slice arr) (PrimState m) b
MutableSliced (Slice arr) (PrimState m) b
xs Int
0 Int
lengthMut
{-# INLINE cloneMut_ #-}
cloneMut_ :: Mutable (Slice arr) (PrimState m) b
-> Int -> Int -> m (Mutable (Slice arr) (PrimState m) b)
cloneMut_ MutableSlice{offsetMut,baseMut} Int
off' Int
len' = do
Mutable arr (PrimState m) b
baseMut' <- Mutable arr (PrimState m) b
-> Int -> Int -> m (Mutable arr (PrimState m) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b
-> Int -> Int -> m (Mutable arr (PrimState m) b)
cloneMut_ (UnliftedMut arr (PrimState m) b -> Mutable arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) b
baseMut) (Int
offsetMut Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
off') Int
len'
MutableSlice arr (PrimState m) b
-> m (MutableSlice arr (PrimState m) b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{offsetMut :: Int
offsetMut=Int
0,lengthMut :: Int
lengthMut=Int
len',baseMut :: UnliftedMut arr (PrimState m) b
baseMut=Mutable arr (PrimState m) b -> UnliftedMut arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable arr (PrimState m) b
baseMut'}
{-# INLINE freeze #-}
freeze :: MutableSliced (Slice arr) (PrimState m) a -> m (Slice arr a)
freeze xs :: MutableSliced (Slice arr) (PrimState m) a
xs@MutableSlice{lengthMut}
= Mutable (Slice arr) (PrimState m) a
-> Int -> Int -> m (Slice arr a)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)
freeze_ Mutable (Slice arr) (PrimState m) a
MutableSliced (Slice arr) (PrimState m) a
xs Int
0 Int
lengthMut
{-# INLINE freeze_ #-}
freeze_ :: Mutable (Slice arr) (PrimState m) b
-> Int -> Int -> m (Slice arr b)
freeze_ MutableSlice{offsetMut,baseMut} Int
off' Int
len' = do
arr b
base <- Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)
freeze_ (UnliftedMut arr (PrimState m) b -> Mutable arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) b
baseMut) (Int
offsetMut Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
off') Int
len'
Slice arr b -> m (Slice arr b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Int
len',base :: Unlifted arr b
base=arr b -> Unlifted arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift arr b
base}
{-# INLINE unsafeShrinkAndFreeze #-}
unsafeShrinkAndFreeze :: Mutable (Slice arr) (PrimState m) a -> Int -> m (Slice arr a)
unsafeShrinkAndFreeze MutableSlice{offsetMut=0,lengthMut,baseMut} Int
len' = do
Mutable arr (PrimState m) a
shrunk <- if Int
lengthMut Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
len'
then Mutable arr (PrimState m) a
-> Int -> m (Mutable arr (PrimState m) a)
forall (arr :: * -> *) (m :: * -> *) b.
(ContiguousU arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b
-> Int -> m (Mutable arr (PrimState m) b)
resize (UnliftedMut arr (PrimState m) a -> Mutable arr (PrimState m) a
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) a
baseMut) Int
len'
else Mutable arr (PrimState m) a -> m (Mutable arr (PrimState m) a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UnliftedMut arr (PrimState m) a -> Mutable arr (PrimState m) a
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) a
baseMut)
arr a
base <- Mutable arr (PrimState m) a -> m (arr a)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m (arr b)
unsafeFreeze Mutable arr (PrimState m) a
shrunk
Slice arr a -> m (Slice arr a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Int
len',base :: Unlifted arr a
base=arr a -> Unlifted arr a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift arr a
base}
unsafeShrinkAndFreeze MutableSlice{offsetMut,baseMut} Int
len' = do
arr a
base <- Mutable arr (PrimState m) a -> Int -> Int -> m (arr a)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)
freeze_ (UnliftedMut arr (PrimState m) a -> Mutable arr (PrimState m) a
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) a
baseMut) Int
offsetMut Int
len'
Slice arr a -> m (Slice arr a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Int
len',base :: Unlifted arr a
base=arr a -> Unlifted arr a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift arr a
base}
{-# INLINE thaw #-}
thaw :: Sliced (Slice arr) b -> m (Mutable (Slice arr) (PrimState m) b)
thaw xs :: Sliced (Slice arr) b
xs@Slice{length} = Slice arr b
-> Int -> Int -> m (Mutable (Slice arr) (PrimState m) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
arr b -> Int -> Int -> m (Mutable arr (PrimState m) b)
thaw_ Sliced (Slice arr) b
Slice arr b
xs Int
0 Int
length
{-# INLINE thaw_ #-}
thaw_ :: Slice arr b
-> Int -> Int -> m (Mutable (Slice arr) (PrimState m) b)
thaw_ Slice{Int
offset :: Int
offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset,Unlifted arr b
base :: Unlifted arr b
base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base} Int
off' Int
len' = do
Mutable arr (PrimState m) b
baseMut <- arr b -> Int -> Int -> m (Mutable arr (PrimState m) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
arr b -> Int -> Int -> m (Mutable arr (PrimState m) b)
thaw_ (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) (Int
offset Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
off') Int
len'
MutableSlice arr (PrimState m) b
-> m (MutableSlice arr (PrimState m) b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{offsetMut :: Int
offsetMut=Int
0,lengthMut :: Int
lengthMut=Int
len',baseMut :: UnliftedMut arr (PrimState m) b
baseMut=Mutable arr (PrimState m) b -> UnliftedMut arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable arr (PrimState m) b
baseMut}
{-# INLINE toSlice #-}
toSlice :: Slice arr a -> Sliced (Slice arr) a
toSlice = Slice arr a -> Sliced (Slice arr) a
forall a. a -> a
id
{-# INLINE toSliceMut #-}
toSliceMut :: Mutable (Slice arr) (PrimState m) a
-> m (MutableSliced (Slice arr) (PrimState m) a)
toSliceMut = Mutable (Slice arr) (PrimState m) a
-> m (MutableSliced (Slice arr) (PrimState m) a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE copy #-}
copy :: Mutable (Slice arr) (PrimState m) b
-> Int -> Sliced (Slice arr) b -> m ()
copy Mutable (Slice arr) (PrimState m) b
dst Int
dstOff src :: Sliced (Slice arr) b
src@Slice{length} = Mutable (Slice arr) (PrimState m) b
-> Int -> Slice arr b -> Int -> Int -> m ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()
copy_ Mutable (Slice arr) (PrimState m) b
dst Int
dstOff Sliced (Slice arr) b
Slice arr b
src Int
0 Int
length
{-# INLINE copy_ #-}
copy_ :: Mutable (Slice arr) (PrimState m) b
-> Int -> Slice arr b -> Int -> Int -> m ()
copy_ MutableSlice{offsetMut,baseMut} Int
dstOff Slice{Int
offset :: Int
offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset,Unlifted arr b
base :: Unlifted arr b
base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base} Int
off' Int
len =
Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()
copy_ (UnliftedMut arr (PrimState m) b -> Mutable arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) b
baseMut) (Int
offsetMut Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
dstOff) (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) (Int
offset Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
off') Int
len
{-# INLINE copyMut #-}
copyMut :: Mutable (Slice arr) (PrimState m) b
-> Int -> MutableSliced (Slice arr) (PrimState m) b -> m ()
copyMut Mutable (Slice arr) (PrimState m) b
dst Int
dstOff src :: MutableSliced (Slice arr) (PrimState m) b
src@MutableSlice{lengthMut} = Mutable (Slice arr) (PrimState m) b
-> Int -> Mutable (Slice arr) (PrimState m) b -> Int -> Int -> m ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b
-> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m ()
copyMut_ Mutable (Slice arr) (PrimState m) b
dst Int
dstOff Mutable (Slice arr) (PrimState m) b
MutableSliced (Slice arr) (PrimState m) b
src Int
0 Int
lengthMut
{-# INLINE copyMut_ #-}
copyMut_ :: Mutable (Slice arr) (PrimState m) b
-> Int -> Mutable (Slice arr) (PrimState m) b -> Int -> Int -> m ()
copyMut_ MutableSlice{offsetMut=dstOff,baseMut=dst} Int
dstOff'
MutableSlice{offsetMut=srcOff,baseMut=src} Int
srcOff' Int
len =
Mutable arr (PrimState m) b
-> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b
-> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m ()
copyMut_ (UnliftedMut arr (PrimState m) b -> Mutable arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) b
dst) (Int
dstOff Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
dstOff') (UnliftedMut arr (PrimState m) b -> Mutable arr (PrimState m) b
forall (arr :: * -> *) s b.
ContiguousU arr =>
UnliftedMut arr s b -> Mutable arr s b
liftMut UnliftedMut arr (PrimState m) b
src) (Int
srcOff Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
srcOff') Int
len
{-# INLINE insertAt #-}
insertAt :: Slice arr b -> Int -> b -> Slice arr b
insertAt Slice{Int
offset :: Int
offset :: forall (arr :: * -> *) a. Slice arr a -> Int
offset,Int
length :: Int
length :: forall (arr :: * -> *) a. Slice arr a -> Int
length,Unlifted arr b
base :: Unlifted arr b
base :: forall (arr :: * -> *) a. Slice arr a -> Unlifted arr a
base} Int
i b
x = (forall s. ST s (Slice arr b)) -> Slice arr b
forall (arr :: * -> *) a.
Contiguous arr =>
(forall s. ST s (arr a)) -> arr a
run ((forall s. ST s (Slice arr b)) -> Slice arr b)
-> (forall s. ST s (Slice arr b)) -> Slice arr b
forall a b. (a -> b) -> a -> b
$ do
Mutable arr s b
dst <- Int -> b -> ST s (Mutable arr (PrimState (ST s)) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Int -> b -> m (Mutable arr (PrimState m) b)
replicateMut (Int
length Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) b
x
Mutable arr (PrimState (ST s)) b
-> Int -> arr b -> Int -> Int -> ST s ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()
copy_ Mutable arr s b
Mutable arr (PrimState (ST s)) b
dst Int
0 (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) Int
offset Int
i
Mutable arr (PrimState (ST s)) b
-> Int -> arr b -> Int -> Int -> ST s ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()
copy_ Mutable arr s b
Mutable arr (PrimState (ST s)) b
dst (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Unlifted arr b -> arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted arr b
base) (Int
offset Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i) (Int
length Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i)
arr b
base' <- Mutable arr (PrimState (ST s)) b -> ST s (arr b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m (arr b)
unsafeFreeze Mutable arr s b
Mutable arr (PrimState (ST s)) b
dst
Slice arr b -> ST s (Slice arr b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Int
lengthInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1,base :: Unlifted arr b
base=arr b -> Unlifted arr b
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift arr b
base'}
{-# INLINE rnf #-}
rnf :: Slice arr a -> ()
rnf !arr :: Slice arr a
arr@Slice{Int
length :: Int
length :: forall (arr :: * -> *) a. Slice arr a -> Int
length} =
let go :: Int -> ()
go !Int
ix = if Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
length
then
let !(# a
x #) = Slice arr a -> Int -> (# a #)
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int -> (# b #)
index# Slice arr a
arr Int
ix
in a -> ()
forall a. NFData a => a -> ()
DS.rnf a
x () -> () -> ()
`seq` Int -> ()
go (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
else ()
in Int -> ()
go Int
0
{-# INLINE run #-}
run :: (forall s. ST s (Slice arr a)) -> Slice arr a
run = (forall s. ST s (Slice arr a)) -> Slice arr a
forall a. (forall s. ST s a) -> a
runST
instance Contiguous SmallArray where
type Mutable SmallArray = SmallMutableArray
type Element SmallArray = Always
type Sliced SmallArray = Slice SmallArray
type MutableSliced SmallArray = MutableSlice SmallArray
{-# INLINE new #-}
new :: Int -> m (Mutable SmallArray (PrimState m) b)
new Int
n = Int -> b -> m (SmallMutableArray (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (SmallMutableArray (PrimState m) a)
newSmallArray Int
n b
forall a. a
errorThunk
{-# INLINE empty #-}
empty :: SmallArray a
empty = SmallArray a
forall a. Monoid a => a
mempty
{-# INLINE index #-}
index :: SmallArray b -> Int -> b
index = SmallArray b -> Int -> b
forall a. SmallArray a -> Int -> a
indexSmallArray
{-# INLINE indexM #-}
indexM :: SmallArray b -> Int -> m b
indexM = SmallArray b -> Int -> m b
forall (m :: * -> *) a. Monad m => SmallArray a -> Int -> m a
indexSmallArrayM
{-# INLINE index# #-}
index# :: SmallArray b -> Int -> (# b #)
index# = SmallArray b -> Int -> (# b #)
forall a. SmallArray a -> Int -> (# a #)
indexSmallArray##
{-# INLINE read #-}
read :: Mutable SmallArray (PrimState m) b -> Int -> m b
read = Mutable SmallArray (PrimState m) b -> Int -> m b
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> m a
readSmallArray
{-# INLINE write #-}
write :: Mutable SmallArray (PrimState m) b -> Int -> b -> m ()
write = Mutable SmallArray (PrimState m) b -> Int -> b -> m ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray
{-# INLINE null #-}
null :: SmallArray b -> Bool
null SmallArray b
a = case SmallArray b -> Int
forall a. SmallArray a -> Int
sizeofSmallArray SmallArray b
a of
Int
0 -> Bool
True
Int
_ -> Bool
False
{-# INLINE slice #-}
slice :: SmallArray a -> Int -> Int -> Sliced SmallArray a
slice SmallArray a
base Int
offset Int
length = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{Int
offset :: Int
offset :: Int
offset,Int
length :: Int
length :: Int
length,base :: Unlifted SmallArray a
base=SmallArray a -> Unlifted SmallArray a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift SmallArray a
base}
{-# INLINE sliceMut #-}
sliceMut :: Mutable SmallArray s a
-> Int -> Int -> MutableSliced SmallArray s a
sliceMut Mutable SmallArray s a
baseMut Int
offsetMut Int
lengthMut = MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{Int
offsetMut :: Int
offsetMut :: Int
offsetMut,Int
lengthMut :: Int
lengthMut :: Int
lengthMut,baseMut :: UnliftedMut SmallArray s a
baseMut=Mutable SmallArray s a -> UnliftedMut SmallArray s a
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable SmallArray s a
baseMut}
{-# INLINE toSlice #-}
toSlice :: SmallArray a -> Sliced SmallArray a
toSlice SmallArray a
base = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=SmallArray a -> Int
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int
size SmallArray a
base,base :: Unlifted SmallArray a
base=SmallArray a -> Unlifted SmallArray a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift SmallArray a
base}
{-# INLINE toSliceMut #-}
toSliceMut :: Mutable SmallArray (PrimState m) a
-> m (MutableSliced SmallArray (PrimState m) a)
toSliceMut Mutable SmallArray (PrimState m) a
baseMut = do
Int
lengthMut <- Mutable SmallArray (PrimState m) a -> m Int
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m Int
sizeMut Mutable SmallArray (PrimState m) a
baseMut
MutableSlice SmallArray (PrimState m) a
-> m (MutableSlice SmallArray (PrimState m) a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{offsetMut :: Int
offsetMut=Int
0,Int
lengthMut :: Int
lengthMut :: Int
lengthMut,baseMut :: UnliftedMut SmallArray (PrimState m) a
baseMut=Mutable SmallArray (PrimState m) a
-> UnliftedMut SmallArray (PrimState m) a
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable SmallArray (PrimState m) a
baseMut}
{-# INLINE freeze_ #-}
freeze_ :: Mutable SmallArray (PrimState m) b
-> Int -> Int -> m (SmallArray b)
freeze_ = Mutable SmallArray (PrimState m) b
-> Int -> Int -> m (SmallArray b)
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> Int -> m (SmallArray a)
freezeSmallArray
{-# INLINE unsafeFreeze #-}
unsafeFreeze :: Mutable SmallArray (PrimState m) b -> m (SmallArray b)
unsafeFreeze = Mutable SmallArray (PrimState m) b -> m (SmallArray b)
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> m (SmallArray a)
unsafeFreezeSmallArray
{-# INLINE size #-}
size :: SmallArray b -> Int
size = SmallArray b -> Int
forall a. SmallArray a -> Int
sizeofSmallArray
{-# INLINE sizeMut #-}
sizeMut :: Mutable SmallArray (PrimState m) b -> m Int
sizeMut = (\Mutable SmallArray (PrimState m) b
x -> Int -> m Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int -> m Int) -> Int -> m Int
forall a b. (a -> b) -> a -> b
$! SmallMutableArray (PrimState m) b -> Int
forall s a. SmallMutableArray s a -> Int
sizeofSmallMutableArray SmallMutableArray (PrimState m) b
Mutable SmallArray (PrimState m) b
x)
{-# INLINE thaw_ #-}
thaw_ :: SmallArray b
-> Int -> Int -> m (Mutable SmallArray (PrimState m) b)
thaw_ = SmallArray b
-> Int -> Int -> m (Mutable SmallArray (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
SmallArray a -> Int -> Int -> m (SmallMutableArray (PrimState m) a)
thawSmallArray
{-# INLINE equals #-}
equals :: SmallArray b -> SmallArray b -> Bool
equals = SmallArray b -> SmallArray b -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE equalsMut #-}
equalsMut :: Mutable SmallArray s a -> Mutable SmallArray s a -> Bool
equalsMut = Mutable SmallArray s a -> Mutable SmallArray s a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE singleton #-}
singleton :: a -> SmallArray a
singleton a
a = (forall s. ST s (SmallArray a)) -> SmallArray a
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SmallArray a)) -> SmallArray a)
-> (forall s. ST s (SmallArray a)) -> SmallArray a
forall a b. (a -> b) -> a -> b
$ do
SmallMutableArray s a
marr <- Int -> a -> ST s (SmallMutableArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (SmallMutableArray (PrimState m) a)
newSmallArray Int
1 a
forall a. a
errorThunk
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
marr Int
0 a
a
SmallMutableArray (PrimState (ST s)) a -> ST s (SmallArray a)
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> m (SmallArray a)
unsafeFreezeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
marr
{-# INLINE doubleton #-}
doubleton :: a -> a -> SmallArray a
doubleton a
a a
b = (forall s. ST s (SmallArray a)) -> SmallArray a
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SmallArray a)) -> SmallArray a)
-> (forall s. ST s (SmallArray a)) -> SmallArray a
forall a b. (a -> b) -> a -> b
$ do
SmallMutableArray s a
m <- Int -> a -> ST s (SmallMutableArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (SmallMutableArray (PrimState m) a)
newSmallArray Int
2 a
forall a. a
errorThunk
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m Int
0 a
a
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m Int
1 a
b
SmallMutableArray (PrimState (ST s)) a -> ST s (SmallArray a)
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> m (SmallArray a)
unsafeFreezeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m
{-# INLINE tripleton #-}
tripleton :: a -> a -> a -> SmallArray a
tripleton a
a a
b a
c = (forall s. ST s (SmallArray a)) -> SmallArray a
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SmallArray a)) -> SmallArray a)
-> (forall s. ST s (SmallArray a)) -> SmallArray a
forall a b. (a -> b) -> a -> b
$ do
SmallMutableArray s a
m <- Int -> a -> ST s (SmallMutableArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (SmallMutableArray (PrimState m) a)
newSmallArray Int
3 a
forall a. a
errorThunk
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m Int
0 a
a
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m Int
1 a
b
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m Int
2 a
c
SmallMutableArray (PrimState (ST s)) a -> ST s (SmallArray a)
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> m (SmallArray a)
unsafeFreezeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m
{-# INLINE quadrupleton #-}
quadrupleton :: a -> a -> a -> a -> SmallArray a
quadrupleton a
a a
b a
c a
d = (forall s. ST s (SmallArray a)) -> SmallArray a
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SmallArray a)) -> SmallArray a)
-> (forall s. ST s (SmallArray a)) -> SmallArray a
forall a b. (a -> b) -> a -> b
$ do
SmallMutableArray s a
m <- Int -> a -> ST s (SmallMutableArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (SmallMutableArray (PrimState m) a)
newSmallArray Int
4 a
forall a. a
errorThunk
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m Int
0 a
a
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m Int
1 a
b
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m Int
2 a
c
SmallMutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m Int
3 a
d
SmallMutableArray (PrimState (ST s)) a -> ST s (SmallArray a)
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> m (SmallArray a)
unsafeFreezeSmallArray SmallMutableArray s a
SmallMutableArray (PrimState (ST s)) a
m
{-# INLINE rnf #-}
rnf :: SmallArray a -> ()
rnf !SmallArray a
ary =
let !sz :: Int
sz = SmallArray a -> Int
forall a. SmallArray a -> Int
sizeofSmallArray SmallArray a
ary
go :: Int -> ()
go !Int
ix = if Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
sz
then
let !(# a
x #) = SmallArray a -> Int -> (# a #)
forall a. SmallArray a -> Int -> (# a #)
indexSmallArray## SmallArray a
ary Int
ix
in a -> ()
forall a. NFData a => a -> ()
DS.rnf a
x () -> () -> ()
`seq` Int -> ()
go (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
else ()
in Int -> ()
go Int
0
{-# INLINE clone_ #-}
clone_ :: SmallArray a -> Int -> Int -> SmallArray a
clone_ = SmallArray a -> Int -> Int -> SmallArray a
forall a. SmallArray a -> Int -> Int -> SmallArray a
cloneSmallArray
{-# INLINE cloneMut_ #-}
cloneMut_ :: Mutable SmallArray (PrimState m) b
-> Int -> Int -> m (Mutable SmallArray (PrimState m) b)
cloneMut_ = Mutable SmallArray (PrimState m) b
-> Int -> Int -> m (Mutable SmallArray (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a
-> Int -> Int -> m (SmallMutableArray (PrimState m) a)
cloneSmallMutableArray
{-# INLINE copy_ #-}
copy_ :: Mutable SmallArray (PrimState m) b
-> Int -> SmallArray b -> Int -> Int -> m ()
copy_ = Mutable SmallArray (PrimState m) b
-> Int -> SmallArray b -> Int -> Int -> m ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a
-> Int -> SmallArray a -> Int -> Int -> m ()
copySmallArray
{-# INLINE copyMut_ #-}
copyMut_ :: Mutable SmallArray (PrimState m) b
-> Int -> Mutable SmallArray (PrimState m) b -> Int -> Int -> m ()
copyMut_ = Mutable SmallArray (PrimState m) b
-> Int -> Mutable SmallArray (PrimState m) b -> Int -> Int -> m ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a
-> Int -> SmallMutableArray (PrimState m) a -> Int -> Int -> m ()
copySmallMutableArray
{-# INLINE replicateMut #-}
replicateMut :: Int -> b -> m (Mutable SmallArray (PrimState m) b)
replicateMut = Int -> b -> m (Mutable SmallArray (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (SmallMutableArray (PrimState m) a)
replicateSmallMutableArray
{-# INLINE run #-}
run :: (forall s. ST s (SmallArray a)) -> SmallArray a
run = (forall s. ST s (SmallArray a)) -> SmallArray a
forall a. (forall s. ST s (SmallArray a)) -> SmallArray a
runSmallArrayST
instance ContiguousU SmallArray where
type Unlifted SmallArray = SmallArray#
type UnliftedMut SmallArray = SmallMutableArray#
{-# INLINE resize #-}
resize :: Mutable SmallArray (PrimState m) b
-> Int -> m (Mutable SmallArray (PrimState m) b)
resize = Mutable SmallArray (PrimState m) b
-> Int -> m (Mutable SmallArray (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a
-> Int -> m (SmallMutableArray (PrimState m) a)
resizeSmallArray
{-# INLINE unlift #-}
unlift :: SmallArray b -> Unlifted SmallArray b
unlift (SmallArray SmallArray# b
x) = SmallArray# b
Unlifted SmallArray b
x
{-# INLINE unliftMut #-}
unliftMut :: Mutable SmallArray s b -> UnliftedMut SmallArray s b
unliftMut (SmallMutableArray x) = SmallMutableArray# s b
UnliftedMut SmallArray s b
x
{-# INLINE lift #-}
lift :: Unlifted SmallArray b -> SmallArray b
lift Unlifted SmallArray b
x = SmallArray# b -> SmallArray b
forall a. SmallArray# a -> SmallArray a
SmallArray SmallArray# b
Unlifted SmallArray b
x
{-# INLINE liftMut #-}
liftMut :: UnliftedMut SmallArray s b -> Mutable SmallArray s b
liftMut UnliftedMut SmallArray s b
x = SmallMutableArray# s b -> SmallMutableArray s b
forall s a. SmallMutableArray# s a -> SmallMutableArray s a
SmallMutableArray SmallMutableArray# s b
UnliftedMut SmallArray s b
x
instance Contiguous PrimArray where
type Mutable PrimArray = MutablePrimArray
type Element PrimArray = Prim
type Sliced PrimArray = Slice PrimArray
type MutableSliced PrimArray = MutableSlice PrimArray
{-# INLINE empty #-}
empty :: PrimArray a
empty = PrimArray a
forall a. Monoid a => a
mempty
{-# INLINE new #-}
new :: Int -> m (Mutable PrimArray (PrimState m) b)
new = Int -> m (Mutable PrimArray (PrimState m) b)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Int -> m (MutablePrimArray (PrimState m) a)
newPrimArray
{-# INLINE replicateMut #-}
replicateMut :: Int -> b -> m (Mutable PrimArray (PrimState m) b)
replicateMut = Int -> b -> m (Mutable PrimArray (PrimState m) b)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Int -> a -> m (MutablePrimArray (PrimState m) a)
replicateMutablePrimArray
{-# INLINE index #-}
index :: PrimArray b -> Int -> b
index = PrimArray b -> Int -> b
forall a. Prim a => PrimArray a -> Int -> a
indexPrimArray
{-# INLINE index# #-}
index# :: PrimArray b -> Int -> (# b #)
index# PrimArray b
arr Int
ix = (# PrimArray b -> Int -> b
forall a. Prim a => PrimArray a -> Int -> a
indexPrimArray PrimArray b
arr Int
ix #)
{-# INLINE indexM #-}
indexM :: PrimArray b -> Int -> m b
indexM PrimArray b
arr Int
ix = b -> m b
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PrimArray b -> Int -> b
forall a. Prim a => PrimArray a -> Int -> a
indexPrimArray PrimArray b
arr Int
ix)
{-# INLINE read #-}
read :: Mutable PrimArray (PrimState m) b -> Int -> m b
read = Mutable PrimArray (PrimState m) b -> Int -> m b
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> m a
readPrimArray
{-# INLINE write #-}
write :: Mutable PrimArray (PrimState m) b -> Int -> b -> m ()
write = Mutable PrimArray (PrimState m) b -> Int -> b -> m ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray
{-# INLINE size #-}
size :: PrimArray b -> Int
size = PrimArray b -> Int
forall a. Prim a => PrimArray a -> Int
sizeofPrimArray
{-# INLINE sizeMut #-}
sizeMut :: Mutable PrimArray (PrimState m) b -> m Int
sizeMut = Mutable PrimArray (PrimState m) b -> m Int
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
MutablePrimArray (PrimState m) a -> m Int
getSizeofMutablePrimArray
{-# INLINE slice #-}
slice :: PrimArray a -> Int -> Int -> Sliced PrimArray a
slice PrimArray a
base Int
offset Int
length = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{Int
offset :: Int
offset :: Int
offset,Int
length :: Int
length :: Int
length,base :: Unlifted PrimArray a
base=PrimArray a -> Unlifted PrimArray a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift PrimArray a
base}
{-# INLINE sliceMut #-}
sliceMut :: Mutable PrimArray s a -> Int -> Int -> MutableSliced PrimArray s a
sliceMut Mutable PrimArray s a
baseMut Int
offsetMut Int
lengthMut = MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{Int
offsetMut :: Int
offsetMut :: Int
offsetMut,Int
lengthMut :: Int
lengthMut :: Int
lengthMut,baseMut :: UnliftedMut PrimArray s a
baseMut=Mutable PrimArray s a -> UnliftedMut PrimArray s a
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable PrimArray s a
baseMut}
{-# INLINE toSlice #-}
toSlice :: PrimArray a -> Sliced PrimArray a
toSlice PrimArray a
base = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=PrimArray a -> Int
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int
size PrimArray a
base,base :: Unlifted PrimArray a
base=PrimArray a -> Unlifted PrimArray a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift PrimArray a
base}
{-# INLINE toSliceMut #-}
toSliceMut :: Mutable PrimArray (PrimState m) a
-> m (MutableSliced PrimArray (PrimState m) a)
toSliceMut Mutable PrimArray (PrimState m) a
baseMut = do
Int
lengthMut <- Mutable PrimArray (PrimState m) a -> m Int
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m Int
sizeMut Mutable PrimArray (PrimState m) a
baseMut
MutableSlice PrimArray (PrimState m) a
-> m (MutableSlice PrimArray (PrimState m) a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{offsetMut :: Int
offsetMut=Int
0,Int
lengthMut :: Int
lengthMut :: Int
lengthMut,baseMut :: UnliftedMut PrimArray (PrimState m) a
baseMut=Mutable PrimArray (PrimState m) a
-> UnliftedMut PrimArray (PrimState m) a
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable PrimArray (PrimState m) a
baseMut}
{-# INLINE freeze_ #-}
freeze_ :: Mutable PrimArray (PrimState m) b -> Int -> Int -> m (PrimArray b)
freeze_ = Mutable PrimArray (PrimState m) b -> Int -> Int -> m (PrimArray b)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
MutablePrimArray (PrimState m) a -> Int -> Int -> m (PrimArray a)
freezePrimArrayShim
{-# INLINE unsafeFreeze #-}
unsafeFreeze :: Mutable PrimArray (PrimState m) b -> m (PrimArray b)
unsafeFreeze = Mutable PrimArray (PrimState m) b -> m (PrimArray b)
forall (m :: * -> *) a.
PrimMonad m =>
MutablePrimArray (PrimState m) a -> m (PrimArray a)
unsafeFreezePrimArray
{-# INLINE thaw_ #-}
thaw_ :: PrimArray b -> Int -> Int -> m (Mutable PrimArray (PrimState m) b)
thaw_ = PrimArray b -> Int -> Int -> m (Mutable PrimArray (PrimState m) b)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
PrimArray a -> Int -> Int -> m (MutablePrimArray (PrimState m) a)
thawPrimArray
{-# INLINE copy_ #-}
copy_ :: Mutable PrimArray (PrimState m) b
-> Int -> PrimArray b -> Int -> Int -> m ()
copy_ = Mutable PrimArray (PrimState m) b
-> Int -> PrimArray b -> Int -> Int -> m ()
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
MutablePrimArray (PrimState m) a
-> Int -> PrimArray a -> Int -> Int -> m ()
copyPrimArray
{-# INLINE copyMut_ #-}
copyMut_ :: Mutable PrimArray (PrimState m) b
-> Int -> Mutable PrimArray (PrimState m) b -> Int -> Int -> m ()
copyMut_ = Mutable PrimArray (PrimState m) b
-> Int -> Mutable PrimArray (PrimState m) b -> Int -> Int -> m ()
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
MutablePrimArray (PrimState m) a
-> Int -> MutablePrimArray (PrimState m) a -> Int -> Int -> m ()
copyMutablePrimArray
{-# INLINE clone_ #-}
clone_ :: PrimArray a -> Int -> Int -> PrimArray a
clone_ = PrimArray a -> Int -> Int -> PrimArray a
forall a. Prim a => PrimArray a -> Int -> Int -> PrimArray a
clonePrimArrayShim
{-# INLINE cloneMut_ #-}
cloneMut_ :: Mutable PrimArray (PrimState m) b
-> Int -> Int -> m (Mutable PrimArray (PrimState m) b)
cloneMut_ = Mutable PrimArray (PrimState m) b
-> Int -> Int -> m (Mutable PrimArray (PrimState m) b)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
MutablePrimArray (PrimState m) a
-> Int -> Int -> m (MutablePrimArray (PrimState m) a)
cloneMutablePrimArrayShim
{-# INLINE equals #-}
equals :: PrimArray b -> PrimArray b -> Bool
equals = PrimArray b -> PrimArray b -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE null #-}
null :: PrimArray b -> Bool
null (PrimArray ByteArray#
a) = case ByteArray# -> Int#
sizeofByteArray# ByteArray#
a of
Int#
0# -> Bool
True
Int#
_ -> Bool
False
{-# INLINE equalsMut #-}
equalsMut :: Mutable PrimArray s a -> Mutable PrimArray s a -> Bool
equalsMut = Mutable PrimArray s a -> Mutable PrimArray s a -> Bool
forall s a. MutablePrimArray s a -> MutablePrimArray s a -> Bool
sameMutablePrimArray
{-# INLINE rnf #-}
rnf :: PrimArray a -> ()
rnf (PrimArray !ByteArray#
_) = ()
{-# INLINE singleton #-}
singleton :: a -> PrimArray a
singleton a
a = (forall s. ST s (PrimArray a)) -> PrimArray a
forall a. (forall s. ST s (PrimArray a)) -> PrimArray a
runPrimArrayST ((forall s. ST s (PrimArray a)) -> PrimArray a)
-> (forall s. ST s (PrimArray a)) -> PrimArray a
forall a b. (a -> b) -> a -> b
$ do
MutablePrimArray s a
marr <- Int -> ST s (MutablePrimArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Int -> m (MutablePrimArray (PrimState m) a)
newPrimArray Int
1
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
marr Int
0 a
a
MutablePrimArray (PrimState (ST s)) a -> ST s (PrimArray a)
forall (m :: * -> *) a.
PrimMonad m =>
MutablePrimArray (PrimState m) a -> m (PrimArray a)
unsafeFreezePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
marr
{-# INLINE doubleton #-}
doubleton :: a -> a -> PrimArray a
doubleton a
a a
b = (forall s. ST s (PrimArray a)) -> PrimArray a
forall a. (forall s. ST s (PrimArray a)) -> PrimArray a
runPrimArrayST ((forall s. ST s (PrimArray a)) -> PrimArray a)
-> (forall s. ST s (PrimArray a)) -> PrimArray a
forall a b. (a -> b) -> a -> b
$ do
MutablePrimArray s a
m <- Int -> ST s (MutablePrimArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Int -> m (MutablePrimArray (PrimState m) a)
newPrimArray Int
2
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m Int
0 a
a
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m Int
1 a
b
MutablePrimArray (PrimState (ST s)) a -> ST s (PrimArray a)
forall (m :: * -> *) a.
PrimMonad m =>
MutablePrimArray (PrimState m) a -> m (PrimArray a)
unsafeFreezePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m
{-# INLINE tripleton #-}
tripleton :: a -> a -> a -> PrimArray a
tripleton a
a a
b a
c = (forall s. ST s (PrimArray a)) -> PrimArray a
forall a. (forall s. ST s (PrimArray a)) -> PrimArray a
runPrimArrayST ((forall s. ST s (PrimArray a)) -> PrimArray a)
-> (forall s. ST s (PrimArray a)) -> PrimArray a
forall a b. (a -> b) -> a -> b
$ do
MutablePrimArray s a
m <- Int -> ST s (MutablePrimArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Int -> m (MutablePrimArray (PrimState m) a)
newPrimArray Int
3
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m Int
0 a
a
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m Int
1 a
b
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m Int
2 a
c
MutablePrimArray (PrimState (ST s)) a -> ST s (PrimArray a)
forall (m :: * -> *) a.
PrimMonad m =>
MutablePrimArray (PrimState m) a -> m (PrimArray a)
unsafeFreezePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m
{-# INLINE quadrupleton #-}
quadrupleton :: a -> a -> a -> a -> PrimArray a
quadrupleton a
a a
b a
c a
d = (forall s. ST s (PrimArray a)) -> PrimArray a
forall a. (forall s. ST s (PrimArray a)) -> PrimArray a
runPrimArrayST ((forall s. ST s (PrimArray a)) -> PrimArray a)
-> (forall s. ST s (PrimArray a)) -> PrimArray a
forall a b. (a -> b) -> a -> b
$ do
MutablePrimArray s a
m <- Int -> ST s (MutablePrimArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Int -> m (MutablePrimArray (PrimState m) a)
newPrimArray Int
4
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m Int
0 a
a
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m Int
1 a
b
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m Int
2 a
c
MutablePrimArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutablePrimArray (PrimState m) a -> Int -> a -> m ()
writePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m Int
3 a
d
MutablePrimArray (PrimState (ST s)) a -> ST s (PrimArray a)
forall (m :: * -> *) a.
PrimMonad m =>
MutablePrimArray (PrimState m) a -> m (PrimArray a)
unsafeFreezePrimArray MutablePrimArray s a
MutablePrimArray (PrimState (ST s)) a
m
{-# INLINE insertAt #-}
insertAt :: PrimArray b -> Int -> b -> PrimArray b
insertAt PrimArray b
src Int
i b
x = (forall s. ST s (PrimArray b)) -> PrimArray b
forall a. (forall s. ST s (PrimArray a)) -> PrimArray a
runPrimArrayST ((forall s. ST s (PrimArray b)) -> PrimArray b)
-> (forall s. ST s (PrimArray b)) -> PrimArray b
forall a b. (a -> b) -> a -> b
$ do
MutablePrimArray s b
dst <- Int -> ST s (Mutable PrimArray (PrimState (ST s)) b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Int -> m (Mutable arr (PrimState m) b)
new (PrimArray b -> Int
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int
size PrimArray b
src Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Mutable PrimArray (PrimState (ST s)) b
-> Int -> Sliced PrimArray b -> ST s ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> Sliced arr b -> m ()
copy MutablePrimArray s b
Mutable PrimArray (PrimState (ST s)) b
dst Int
0 (PrimArray b -> Int -> Int -> Sliced PrimArray b
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
arr a -> Int -> Int -> Sliced arr a
slice PrimArray b
src Int
0 Int
i)
Mutable PrimArray (PrimState (ST s)) b -> Int -> b -> ST s ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> b -> m ()
write MutablePrimArray s b
Mutable PrimArray (PrimState (ST s)) b
dst Int
i b
x
Mutable PrimArray (PrimState (ST s)) b
-> Int -> Sliced PrimArray b -> ST s ()
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> Int -> Sliced arr b -> m ()
copy MutablePrimArray s b
Mutable PrimArray (PrimState (ST s)) b
dst (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (PrimArray b -> Int -> Int -> Sliced PrimArray b
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
arr a -> Int -> Int -> Sliced arr a
slice PrimArray b
src Int
i (PrimArray b -> Int
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int
size PrimArray b
src Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i))
Mutable PrimArray (PrimState (ST s)) b -> ST s (PrimArray b)
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m (arr b)
unsafeFreeze MutablePrimArray s b
Mutable PrimArray (PrimState (ST s)) b
dst
{-# INLINE run #-}
run :: (forall s. ST s (PrimArray a)) -> PrimArray a
run = (forall s. ST s (PrimArray a)) -> PrimArray a
forall a. (forall s. ST s (PrimArray a)) -> PrimArray a
runPrimArrayST
newtype PrimArray# a = PrimArray# ByteArray#
newtype MutablePrimArray# s a = MutablePrimArray# (MutableByteArray# s)
instance ContiguousU PrimArray where
type Unlifted PrimArray = PrimArray#
type UnliftedMut PrimArray = MutablePrimArray#
{-# INLINE resize #-}
resize :: Mutable PrimArray (PrimState m) b
-> Int -> m (Mutable PrimArray (PrimState m) b)
resize = Mutable PrimArray (PrimState m) b
-> Int -> m (Mutable PrimArray (PrimState m) b)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
MutablePrimArray (PrimState m) a
-> Int -> m (MutablePrimArray (PrimState m) a)
resizeMutablePrimArray
{-# INLINE unlift #-}
unlift :: PrimArray b -> Unlifted PrimArray b
unlift (PrimArray ByteArray#
x) = ByteArray# -> PrimArray# b
forall a. ByteArray# -> PrimArray# a
PrimArray# ByteArray#
x
{-# INLINE unliftMut #-}
unliftMut :: Mutable PrimArray s b -> UnliftedMut PrimArray s b
unliftMut (MutablePrimArray x) = MutableByteArray# s -> MutablePrimArray# s b
forall s a. MutableByteArray# s -> MutablePrimArray# s a
MutablePrimArray# MutableByteArray# s
x
{-# INLINE lift #-}
lift :: Unlifted PrimArray b -> PrimArray b
lift (PrimArray# x) = ByteArray# -> PrimArray b
forall a. ByteArray# -> PrimArray a
PrimArray ByteArray#
x
{-# INLINE liftMut #-}
liftMut :: UnliftedMut PrimArray s b -> Mutable PrimArray s b
liftMut (MutablePrimArray# x) = MutableByteArray# s -> MutablePrimArray s b
forall s a. MutableByteArray# s -> MutablePrimArray s a
MutablePrimArray MutableByteArray# s
x
instance Contiguous Array where
type Mutable Array = MutableArray
type Element Array = Always
type Sliced Array = Slice Array
type MutableSliced Array = MutableSlice Array
{-# INLINE empty #-}
empty :: Array a
empty = Array a
forall a. Monoid a => a
mempty
{-# INLINE new #-}
new :: Int -> m (Mutable Array (PrimState m) b)
new Int
n = Int -> b -> m (MutableArray (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (MutableArray (PrimState m) a)
newArray Int
n b
forall a. a
errorThunk
{-# INLINE replicateMut #-}
replicateMut :: Int -> b -> m (Mutable Array (PrimState m) b)
replicateMut = Int -> b -> m (Mutable Array (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (MutableArray (PrimState m) a)
newArray
{-# INLINE index #-}
index :: Array b -> Int -> b
index = Array b -> Int -> b
forall a. Array a -> Int -> a
indexArray
{-# INLINE index# #-}
index# :: Array b -> Int -> (# b #)
index# = Array b -> Int -> (# b #)
forall a. Array a -> Int -> (# a #)
indexArray##
{-# INLINE indexM #-}
indexM :: Array b -> Int -> m b
indexM = Array b -> Int -> m b
forall (m :: * -> *) a. Monad m => Array a -> Int -> m a
indexArrayM
{-# INLINE read #-}
read :: Mutable Array (PrimState m) b -> Int -> m b
read = Mutable Array (PrimState m) b -> Int -> m b
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> m a
readArray
{-# INLINE write #-}
write :: Mutable Array (PrimState m) b -> Int -> b -> m ()
write = Mutable Array (PrimState m) b -> Int -> b -> m ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> a -> m ()
writeArray
{-# INLINE size #-}
size :: Array b -> Int
size = Array b -> Int
forall a. Array a -> Int
sizeofArray
{-# INLINE sizeMut #-}
sizeMut :: Mutable Array (PrimState m) b -> m Int
sizeMut = (\Mutable Array (PrimState m) b
x -> Int -> m Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int -> m Int) -> Int -> m Int
forall a b. (a -> b) -> a -> b
$! MutableArray (PrimState m) b -> Int
forall s a. MutableArray s a -> Int
sizeofMutableArray MutableArray (PrimState m) b
Mutable Array (PrimState m) b
x)
{-# INLINE slice #-}
slice :: Array a -> Int -> Int -> Sliced Array a
slice Array a
base Int
offset Int
length = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{Int
offset :: Int
offset :: Int
offset,Int
length :: Int
length :: Int
length,base :: Unlifted Array a
base=Array a -> Unlifted Array a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift Array a
base}
{-# INLINE sliceMut #-}
sliceMut :: Mutable Array s a -> Int -> Int -> MutableSliced Array s a
sliceMut Mutable Array s a
baseMut Int
offsetMut Int
lengthMut = MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{Int
offsetMut :: Int
offsetMut :: Int
offsetMut,Int
lengthMut :: Int
lengthMut :: Int
lengthMut,baseMut :: UnliftedMut Array s a
baseMut=Mutable Array s a -> UnliftedMut Array s a
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable Array s a
baseMut}
{-# INLINE toSlice #-}
toSlice :: Array a -> Sliced Array a
toSlice Array a
base = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=Array a -> Int
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int
size Array a
base,base :: Unlifted Array a
base=Array a -> Unlifted Array a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift Array a
base}
{-# INLINE toSliceMut #-}
toSliceMut :: Mutable Array (PrimState m) a
-> m (MutableSliced Array (PrimState m) a)
toSliceMut Mutable Array (PrimState m) a
baseMut = do
Int
lengthMut <- Mutable Array (PrimState m) a -> m Int
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m Int
sizeMut Mutable Array (PrimState m) a
baseMut
MutableSlice Array (PrimState m) a
-> m (MutableSlice Array (PrimState m) a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{offsetMut :: Int
offsetMut=Int
0,Int
lengthMut :: Int
lengthMut :: Int
lengthMut,baseMut :: UnliftedMut Array (PrimState m) a
baseMut=Mutable Array (PrimState m) a -> UnliftedMut Array (PrimState m) a
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable Array (PrimState m) a
baseMut}
{-# INLINE freeze_ #-}
freeze_ :: Mutable Array (PrimState m) b -> Int -> Int -> m (Array b)
freeze_ = Mutable Array (PrimState m) b -> Int -> Int -> m (Array b)
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> Int -> m (Array a)
freezeArray
{-# INLINE unsafeFreeze #-}
unsafeFreeze :: Mutable Array (PrimState m) b -> m (Array b)
unsafeFreeze = Mutable Array (PrimState m) b -> m (Array b)
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> m (Array a)
unsafeFreezeArray
{-# INLINE thaw_ #-}
thaw_ :: Array b -> Int -> Int -> m (Mutable Array (PrimState m) b)
thaw_ = Array b -> Int -> Int -> m (Mutable Array (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
Array a -> Int -> Int -> m (MutableArray (PrimState m) a)
thawArray
{-# INLINE copy_ #-}
copy_ :: Mutable Array (PrimState m) b
-> Int -> Array b -> Int -> Int -> m ()
copy_ = Mutable Array (PrimState m) b
-> Int -> Array b -> Int -> Int -> m ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a
-> Int -> Array a -> Int -> Int -> m ()
copyArray
{-# INLINE copyMut_ #-}
copyMut_ :: Mutable Array (PrimState m) b
-> Int -> Mutable Array (PrimState m) b -> Int -> Int -> m ()
copyMut_ = Mutable Array (PrimState m) b
-> Int -> Mutable Array (PrimState m) b -> Int -> Int -> m ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a
-> Int -> MutableArray (PrimState m) a -> Int -> Int -> m ()
copyMutableArray
{-# INLINE clone #-}
clone :: Sliced Array b -> Array b
clone Slice{offset,length,base} = Array b -> Int -> Int -> Array b
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
arr a -> Int -> Int -> arr a
clone_ (Unlifted Array b -> Array b
forall (arr :: * -> *) b.
ContiguousU arr =>
Unlifted arr b -> arr b
lift Unlifted Array b
base) Int
offset Int
length
{-# INLINE clone_ #-}
clone_ :: Array a -> Int -> Int -> Array a
clone_ = Array a -> Int -> Int -> Array a
forall a. Array a -> Int -> Int -> Array a
cloneArray
{-# INLINE cloneMut_ #-}
cloneMut_ :: Mutable Array (PrimState m) b
-> Int -> Int -> m (Mutable Array (PrimState m) b)
cloneMut_ = Mutable Array (PrimState m) b
-> Int -> Int -> m (Mutable Array (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a
-> Int -> Int -> m (MutableArray (PrimState m) a)
cloneMutableArray
{-# INLINE equals #-}
equals :: Array b -> Array b -> Bool
equals = Array b -> Array b -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE null #-}
null :: Array b -> Bool
null (Array Array# b
a) = case Array# b -> Int#
forall a. Array# a -> Int#
sizeofArray# Array# b
a of
Int#
0# -> Bool
True
Int#
_ -> Bool
False
{-# INLINE equalsMut #-}
equalsMut :: Mutable Array s a -> Mutable Array s a -> Bool
equalsMut = Mutable Array s a -> Mutable Array s a -> Bool
forall s a. MutableArray s a -> MutableArray s a -> Bool
sameMutableArray
{-# INLINE rnf #-}
rnf :: Array a -> ()
rnf !Array a
ary =
let !sz :: Int
sz = Array a -> Int
forall a. Array a -> Int
sizeofArray Array a
ary
go :: Int -> ()
go !Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
sz = ()
| Bool
otherwise =
let !(# a
x #) = Array a -> Int -> (# a #)
forall a. Array a -> Int -> (# a #)
indexArray## Array a
ary Int
i
in a -> ()
forall a. NFData a => a -> ()
DS.rnf a
x () -> () -> ()
`seq` Int -> ()
go (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
in Int -> ()
go Int
0
{-# INLINE singleton #-}
singleton :: a -> Array a
singleton a
a = (forall s. ST s (Array a)) -> Array a
forall a. (forall s. ST s (Array a)) -> Array a
runArrayST (Int -> a -> ST s (MutableArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (MutableArray (PrimState m) a)
newArray Int
1 a
a ST s (MutableArray s a)
-> (MutableArray s a -> ST s (Array a)) -> ST s (Array a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MutableArray s a -> ST s (Array a)
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> m (Array a)
unsafeFreezeArray)
{-# INLINE doubleton #-}
doubleton :: a -> a -> Array a
doubleton a
a a
b = (forall s. ST s (Array a)) -> Array a
forall a. (forall s. ST s (Array a)) -> Array a
runArrayST ((forall s. ST s (Array a)) -> Array a)
-> (forall s. ST s (Array a)) -> Array a
forall a b. (a -> b) -> a -> b
$ do
MutableArray s a
m <- Int -> a -> ST s (MutableArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (MutableArray (PrimState m) a)
newArray Int
2 a
a
MutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> a -> m ()
writeArray MutableArray s a
MutableArray (PrimState (ST s)) a
m Int
1 a
b
MutableArray (PrimState (ST s)) a -> ST s (Array a)
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> m (Array a)
unsafeFreezeArray MutableArray s a
MutableArray (PrimState (ST s)) a
m
{-# INLINE tripleton #-}
tripleton :: a -> a -> a -> Array a
tripleton a
a a
b a
c = (forall s. ST s (Array a)) -> Array a
forall a. (forall s. ST s (Array a)) -> Array a
runArrayST ((forall s. ST s (Array a)) -> Array a)
-> (forall s. ST s (Array a)) -> Array a
forall a b. (a -> b) -> a -> b
$ do
MutableArray s a
m <- Int -> a -> ST s (MutableArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (MutableArray (PrimState m) a)
newArray Int
3 a
a
MutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> a -> m ()
writeArray MutableArray s a
MutableArray (PrimState (ST s)) a
m Int
1 a
b
MutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> a -> m ()
writeArray MutableArray s a
MutableArray (PrimState (ST s)) a
m Int
2 a
c
MutableArray (PrimState (ST s)) a -> ST s (Array a)
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> m (Array a)
unsafeFreezeArray MutableArray s a
MutableArray (PrimState (ST s)) a
m
{-# INLINE quadrupleton #-}
quadrupleton :: a -> a -> a -> a -> Array a
quadrupleton a
a a
b a
c a
d = (forall s. ST s (Array a)) -> Array a
forall a. (forall s. ST s (Array a)) -> Array a
runArrayST ((forall s. ST s (Array a)) -> Array a)
-> (forall s. ST s (Array a)) -> Array a
forall a b. (a -> b) -> a -> b
$ do
MutableArray s a
m <- Int -> a -> ST s (MutableArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (MutableArray (PrimState m) a)
newArray Int
4 a
a
MutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> a -> m ()
writeArray MutableArray s a
MutableArray (PrimState (ST s)) a
m Int
1 a
b
MutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> a -> m ()
writeArray MutableArray s a
MutableArray (PrimState (ST s)) a
m Int
2 a
c
MutableArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> a -> m ()
writeArray MutableArray s a
MutableArray (PrimState (ST s)) a
m Int
3 a
d
MutableArray (PrimState (ST s)) a -> ST s (Array a)
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> m (Array a)
unsafeFreezeArray MutableArray s a
MutableArray (PrimState (ST s)) a
m
{-# INLINE run #-}
run :: (forall s. ST s (Array a)) -> Array a
run = (forall s. ST s (Array a)) -> Array a
forall a. (forall s. ST s (Array a)) -> Array a
runArrayST
instance ContiguousU Array where
type Unlifted Array = Array#
type UnliftedMut Array = MutableArray#
{-# INLINE resize #-}
resize :: Mutable Array (PrimState m) b
-> Int -> m (Mutable Array (PrimState m) b)
resize = Mutable Array (PrimState m) b
-> Int -> m (Mutable Array (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a
-> Int -> m (MutableArray (PrimState m) a)
resizeArray
{-# INLINE unlift #-}
unlift :: Array b -> Unlifted Array b
unlift (Array Array# b
x) = Array# b
Unlifted Array b
x
{-# INLINE unliftMut #-}
unliftMut :: Mutable Array s b -> UnliftedMut Array s b
unliftMut (MutableArray x) = MutableArray# s b
UnliftedMut Array s b
x
{-# INLINE lift #-}
lift :: Unlifted Array b -> Array b
lift Unlifted Array b
x = Array# b -> Array b
forall a. Array# a -> Array a
Array Array# b
Unlifted Array b
x
{-# INLINE liftMut #-}
liftMut :: UnliftedMut Array s b -> Mutable Array s b
liftMut UnliftedMut Array s b
x = MutableArray# s b -> MutableArray s b
forall s a. MutableArray# s a -> MutableArray s a
MutableArray MutableArray# s b
UnliftedMut Array s b
x
instance Contiguous UnliftedArray where
type Mutable UnliftedArray = MutableUnliftedArray
type Element UnliftedArray = PrimUnlifted
type Sliced UnliftedArray = Slice UnliftedArray
type MutableSliced UnliftedArray = MutableSlice UnliftedArray
{-# INLINE empty #-}
empty :: UnliftedArray a
empty = UnliftedArray a
forall a. UnliftedArray a
emptyUnliftedArray
{-# INLINE new #-}
new :: Int -> m (Mutable UnliftedArray (PrimState m) b)
new = Int -> m (Mutable UnliftedArray (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> m (MutableUnliftedArray (PrimState m) a)
unsafeNewUnliftedArray
{-# INLINE replicateMut #-}
replicateMut :: Int -> b -> m (Mutable UnliftedArray (PrimState m) b)
replicateMut = Int -> b -> m (Mutable UnliftedArray (PrimState m) b)
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
Int -> a -> m (MutableUnliftedArray (PrimState m) a)
newUnliftedArray
{-# INLINE index #-}
index :: UnliftedArray b -> Int -> b
index = UnliftedArray b -> Int -> b
forall a. PrimUnlifted a => UnliftedArray a -> Int -> a
indexUnliftedArray
{-# INLINE index# #-}
index# :: UnliftedArray b -> Int -> (# b #)
index# UnliftedArray b
arr Int
ix = (# UnliftedArray b -> Int -> b
forall a. PrimUnlifted a => UnliftedArray a -> Int -> a
indexUnliftedArray UnliftedArray b
arr Int
ix #)
{-# INLINE indexM #-}
indexM :: UnliftedArray b -> Int -> m b
indexM UnliftedArray b
arr Int
ix = b -> m b
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UnliftedArray b -> Int -> b
forall a. PrimUnlifted a => UnliftedArray a -> Int -> a
indexUnliftedArray UnliftedArray b
arr Int
ix)
{-# INLINE read #-}
read :: Mutable UnliftedArray (PrimState m) b -> Int -> m b
read = Mutable UnliftedArray (PrimState m) b -> Int -> m b
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> m a
readUnliftedArray
{-# INLINE write #-}
write :: Mutable UnliftedArray (PrimState m) b -> Int -> b -> m ()
write = Mutable UnliftedArray (PrimState m) b -> Int -> b -> m ()
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray
{-# INLINE size #-}
size :: UnliftedArray b -> Int
size = UnliftedArray b -> Int
forall e. UnliftedArray e -> Int
sizeofUnliftedArray
{-# INLINE sizeMut #-}
sizeMut :: Mutable UnliftedArray (PrimState m) b -> m Int
sizeMut = Int -> m Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int -> m Int)
-> (MutableUnliftedArray (PrimState m) b -> Int)
-> MutableUnliftedArray (PrimState m) b
-> m Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutableUnliftedArray (PrimState m) b -> Int
forall s e. MutableUnliftedArray s e -> Int
sizeofMutableUnliftedArray
{-# INLINE slice #-}
slice :: UnliftedArray a -> Int -> Int -> Sliced UnliftedArray a
slice UnliftedArray a
base Int
offset Int
length = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{Int
offset :: Int
offset :: Int
offset,Int
length :: Int
length :: Int
length,base :: Unlifted UnliftedArray a
base=UnliftedArray a -> Unlifted UnliftedArray a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift UnliftedArray a
base}
{-# INLINE sliceMut #-}
sliceMut :: Mutable UnliftedArray s a
-> Int -> Int -> MutableSliced UnliftedArray s a
sliceMut Mutable UnliftedArray s a
baseMut Int
offsetMut Int
lengthMut = MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{Int
offsetMut :: Int
offsetMut :: Int
offsetMut,Int
lengthMut :: Int
lengthMut :: Int
lengthMut,baseMut :: UnliftedMut UnliftedArray s a
baseMut=Mutable UnliftedArray s a -> UnliftedMut UnliftedArray s a
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable UnliftedArray s a
baseMut}
{-# INLINE freeze_ #-}
freeze_ :: Mutable UnliftedArray (PrimState m) b
-> Int -> Int -> m (UnliftedArray b)
freeze_ = Mutable UnliftedArray (PrimState m) b
-> Int -> Int -> m (UnliftedArray b)
forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int -> Int -> m (UnliftedArray a)
freezeUnliftedArray
{-# INLINE unsafeFreeze #-}
unsafeFreeze :: Mutable UnliftedArray (PrimState m) b -> m (UnliftedArray b)
unsafeFreeze = Mutable UnliftedArray (PrimState m) b -> m (UnliftedArray b)
forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
unsafeFreezeUnliftedArray
{-# INLINE toSlice #-}
toSlice :: UnliftedArray a -> Sliced UnliftedArray a
toSlice UnliftedArray a
base = Slice :: forall (arr :: * -> *) a.
Int -> Int -> Unlifted arr a -> Slice arr a
Slice{offset :: Int
offset=Int
0,length :: Int
length=UnliftedArray a -> Int
forall (arr :: * -> *) b.
(Contiguous arr, Element arr b) =>
arr b -> Int
size UnliftedArray a
base,base :: Unlifted UnliftedArray a
base=UnliftedArray a -> Unlifted UnliftedArray a
forall (arr :: * -> *) b.
ContiguousU arr =>
arr b -> Unlifted arr b
unlift UnliftedArray a
base}
{-# INLINE toSliceMut #-}
toSliceMut :: Mutable UnliftedArray (PrimState m) a
-> m (MutableSliced UnliftedArray (PrimState m) a)
toSliceMut Mutable UnliftedArray (PrimState m) a
baseMut = do
Int
lengthMut <- Mutable UnliftedArray (PrimState m) a -> m Int
forall (arr :: * -> *) (m :: * -> *) b.
(Contiguous arr, PrimMonad m, Element arr b) =>
Mutable arr (PrimState m) b -> m Int
sizeMut Mutable UnliftedArray (PrimState m) a
baseMut
MutableSlice UnliftedArray (PrimState m) a
-> m (MutableSlice UnliftedArray (PrimState m) a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MutableSlice :: forall (arr :: * -> *) s a.
Int -> Int -> UnliftedMut arr s a -> MutableSlice arr s a
MutableSlice{offsetMut :: Int
offsetMut=Int
0,Int
lengthMut :: Int
lengthMut :: Int
lengthMut,baseMut :: UnliftedMut UnliftedArray (PrimState m) a
baseMut=Mutable UnliftedArray (PrimState m) a
-> UnliftedMut UnliftedArray (PrimState m) a
forall (arr :: * -> *) s b.
ContiguousU arr =>
Mutable arr s b -> UnliftedMut arr s b
unliftMut Mutable UnliftedArray (PrimState m) a
baseMut}
{-# INLINE thaw_ #-}
thaw_ :: UnliftedArray b
-> Int -> Int -> m (Mutable UnliftedArray (PrimState m) b)
thaw_ = UnliftedArray b
-> Int -> Int -> m (Mutable UnliftedArray (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
UnliftedArray a
-> Int -> Int -> m (MutableUnliftedArray (PrimState m) a)
thawUnliftedArray
{-# INLINE copy_ #-}
copy_ :: Mutable UnliftedArray (PrimState m) b
-> Int -> UnliftedArray b -> Int -> Int -> m ()
copy_ = Mutable UnliftedArray (PrimState m) b
-> Int -> UnliftedArray b -> Int -> Int -> m ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int -> UnliftedArray a -> Int -> Int -> m ()
copyUnliftedArray
{-# INLINE copyMut_ #-}
copyMut_ :: Mutable UnliftedArray (PrimState m) b
-> Int
-> Mutable UnliftedArray (PrimState m) b
-> Int
-> Int
-> m ()
copyMut_ = Mutable UnliftedArray (PrimState m) b
-> Int
-> Mutable UnliftedArray (PrimState m) b
-> Int
-> Int
-> m ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int
-> MutableUnliftedArray (PrimState m) a
-> Int
-> Int
-> m ()
copyMutableUnliftedArray
{-# INLINE clone_ #-}
clone_ :: UnliftedArray a -> Int -> Int -> UnliftedArray a
clone_ = UnliftedArray a -> Int -> Int -> UnliftedArray a
forall a. UnliftedArray a -> Int -> Int -> UnliftedArray a
cloneUnliftedArray
{-# INLINE cloneMut_ #-}
cloneMut_ :: Mutable UnliftedArray (PrimState m) b
-> Int -> Int -> m (Mutable UnliftedArray (PrimState m) b)
cloneMut_ = Mutable UnliftedArray (PrimState m) b
-> Int -> Int -> m (Mutable UnliftedArray (PrimState m) b)
forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a
-> Int -> Int -> m (MutableUnliftedArray (PrimState m) a)
cloneMutableUnliftedArray
{-# INLINE equals #-}
equals :: UnliftedArray b -> UnliftedArray b -> Bool
equals = UnliftedArray b -> UnliftedArray b -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE null #-}
null :: UnliftedArray b -> Bool
null (UnliftedArray ArrayArray#
a) = case ArrayArray# -> Int#
sizeofArrayArray# ArrayArray#
a of
Int#
0# -> Bool
True
Int#
_ -> Bool
False
{-# INLINE equalsMut #-}
equalsMut :: Mutable UnliftedArray s a -> Mutable UnliftedArray s a -> Bool
equalsMut = Mutable UnliftedArray s a -> Mutable UnliftedArray s a -> Bool
forall s a.
MutableUnliftedArray s a -> MutableUnliftedArray s a -> Bool
sameMutableUnliftedArray
{-# INLINE rnf #-}
rnf :: UnliftedArray a -> ()
rnf !UnliftedArray a
ary =
let !sz :: Int
sz = UnliftedArray a -> Int
forall e. UnliftedArray e -> Int
sizeofUnliftedArray UnliftedArray a
ary
go :: Int -> ()
go !Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
sz = ()
| Bool
otherwise =
let x :: a
x = UnliftedArray a -> Int -> a
forall a. PrimUnlifted a => UnliftedArray a -> Int -> a
indexUnliftedArray UnliftedArray a
ary Int
i
in a -> ()
forall a. NFData a => a -> ()
DS.rnf a
x () -> () -> ()
`seq` Int -> ()
go (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
in Int -> ()
go Int
0
{-# INLINE singleton #-}
singleton :: a -> UnliftedArray a
singleton a
a = (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
forall a. (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
runUnliftedArrayST (Int -> a -> ST s (MutableUnliftedArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
Int -> a -> m (MutableUnliftedArray (PrimState m) a)
newUnliftedArray Int
1 a
a ST s (MutableUnliftedArray s a)
-> (MutableUnliftedArray s a -> ST s (UnliftedArray a))
-> ST s (UnliftedArray a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MutableUnliftedArray s a -> ST s (UnliftedArray a)
forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
unsafeFreezeUnliftedArray)
{-# INLINE doubleton #-}
doubleton :: a -> a -> UnliftedArray a
doubleton a
a a
b = (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
forall a. (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
runUnliftedArrayST ((forall s. ST s (UnliftedArray a)) -> UnliftedArray a)
-> (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
forall a b. (a -> b) -> a -> b
$ do
MutableUnliftedArray s a
m <- Int -> a -> ST s (MutableUnliftedArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
Int -> a -> m (MutableUnliftedArray (PrimState m) a)
newUnliftedArray Int
2 a
a
MutableUnliftedArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray MutableUnliftedArray s a
MutableUnliftedArray (PrimState (ST s)) a
m Int
1 a
b
MutableUnliftedArray (PrimState (ST s)) a -> ST s (UnliftedArray a)
forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
unsafeFreezeUnliftedArray MutableUnliftedArray s a
MutableUnliftedArray (PrimState (ST s)) a
m
{-# INLINE tripleton #-}
tripleton :: a -> a -> a -> UnliftedArray a
tripleton a
a a
b a
c = (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
forall a. (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
runUnliftedArrayST ((forall s. ST s (UnliftedArray a)) -> UnliftedArray a)
-> (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
forall a b. (a -> b) -> a -> b
$ do
MutableUnliftedArray s a
m <- Int -> a -> ST s (MutableUnliftedArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
Int -> a -> m (MutableUnliftedArray (PrimState m) a)
newUnliftedArray Int
3 a
a
MutableUnliftedArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray MutableUnliftedArray s a
MutableUnliftedArray (PrimState (ST s)) a
m Int
1 a
b
MutableUnliftedArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray MutableUnliftedArray s a
MutableUnliftedArray (PrimState (ST s)) a
m Int
2 a
c
MutableUnliftedArray (PrimState (ST s)) a -> ST s (UnliftedArray a)
forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
unsafeFreezeUnliftedArray MutableUnliftedArray s a
MutableUnliftedArray (PrimState (ST s)) a
m
{-# INLINE quadrupleton #-}
quadrupleton :: a -> a -> a -> a -> UnliftedArray a
quadrupleton a
a a
b a
c a
d = (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
forall a. (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
runUnliftedArrayST ((forall s. ST s (UnliftedArray a)) -> UnliftedArray a)
-> (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
forall a b. (a -> b) -> a -> b
$ do
MutableUnliftedArray s a
m <- Int -> a -> ST s (MutableUnliftedArray (PrimState (ST s)) a)
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
Int -> a -> m (MutableUnliftedArray (PrimState m) a)
newUnliftedArray Int
4 a
a
MutableUnliftedArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray MutableUnliftedArray s a
MutableUnliftedArray (PrimState (ST s)) a
m Int
1 a
b
MutableUnliftedArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray MutableUnliftedArray s a
MutableUnliftedArray (PrimState (ST s)) a
m Int
2 a
c
MutableUnliftedArray (PrimState (ST s)) a -> Int -> a -> ST s ()
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
writeUnliftedArray MutableUnliftedArray s a
MutableUnliftedArray (PrimState (ST s)) a
m Int
3 a
d
MutableUnliftedArray (PrimState (ST s)) a -> ST s (UnliftedArray a)
forall (m :: * -> *) a.
PrimMonad m =>
MutableUnliftedArray (PrimState m) a -> m (UnliftedArray a)
unsafeFreezeUnliftedArray MutableUnliftedArray s a
MutableUnliftedArray (PrimState (ST s)) a
m
{-# INLINE run #-}
run :: (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
run = (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
forall a. (forall s. ST s (UnliftedArray a)) -> UnliftedArray a
runUnliftedArrayST
newtype UnliftedArray# a = UnliftedArray# ArrayArray#
newtype MutableUnliftedArray# s a = MutableUnliftedArray# (MutableArrayArray# s)
instance ContiguousU UnliftedArray where
type Unlifted UnliftedArray = UnliftedArray#
type UnliftedMut UnliftedArray = MutableUnliftedArray#
{-# INLINE resize #-}
resize :: Mutable UnliftedArray (PrimState m) b
-> Int -> m (Mutable UnliftedArray (PrimState m) b)
resize = Mutable UnliftedArray (PrimState m) b
-> Int -> m (Mutable UnliftedArray (PrimState m) b)
forall (m :: * -> *) a.
(PrimMonad m, PrimUnlifted a) =>
MutableUnliftedArray (PrimState m) a
-> Int -> m (MutableUnliftedArray (PrimState m) a)
resizeUnliftedArray
{-# INLINE unlift #-}
unlift :: UnliftedArray b -> Unlifted UnliftedArray b
unlift (UnliftedArray ArrayArray#
x) = (ArrayArray# -> UnliftedArray# b
forall a. ArrayArray# -> UnliftedArray# a
UnliftedArray# ArrayArray#
x)
{-# INLINE unliftMut #-}
unliftMut :: Mutable UnliftedArray s b -> UnliftedMut UnliftedArray s b
unliftMut (MutableUnliftedArray x) = (MutableArrayArray# s -> MutableUnliftedArray# s b
forall s a. MutableArrayArray# s -> MutableUnliftedArray# s a
MutableUnliftedArray# MutableArrayArray# s
x)
{-# INLINE lift #-}
lift :: Unlifted UnliftedArray b -> UnliftedArray b
lift (UnliftedArray# x) = ArrayArray# -> UnliftedArray b
forall a. ArrayArray# -> UnliftedArray a
UnliftedArray ArrayArray#
x
{-# INLINE liftMut #-}
liftMut :: UnliftedMut UnliftedArray s b -> Mutable UnliftedArray s b
liftMut (MutableUnliftedArray# x) = MutableArrayArray# s -> MutableUnliftedArray s b
forall s a. MutableArrayArray# s -> MutableUnliftedArray s a
MutableUnliftedArray MutableArrayArray# s
x