{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE RankNTypes #-}
module Data.Vector.Generic.Mutable.Sized
( MVector
, length
, length'
, null
, slice
, slice'
, init
, tail
, take
, take'
, drop
, drop'
, splitAt
, splitAt'
, overlaps
, new
, unsafeNew
, replicate
, replicate'
, replicateM
, replicateM'
, clone
, grow
, growFront
, clear
, read
, read'
, write
, write'
, modify
, modify'
, swap
, exchange
, exchange'
, unsafeRead
, unsafeWrite
, unsafeModify
, unsafeSwap
, unsafeExchange
, nextPermutation
, set
, copy
, move
, unsafeCopy
, toSized
, withSized
, fromSized
) where
import qualified Data.Vector.Generic.Mutable as VGM
import Data.Vector.Generic.Mutable.Sized.Internal
import GHC.TypeLits
import Data.Finite
import Data.Finite.Internal
import Data.Maybe
import Data.Proxy
import Control.Monad.Primitive
import Prelude hiding ( length, null, replicate, init,
tail, take, drop, splitAt, read )
length :: forall v n s a. KnownNat n
=> MVector v n s a -> Int
length :: forall (v :: * -> * -> *) (n :: Nat) s a.
KnownNat n =>
MVector v n s a -> Int
length MVector v n s a
_ = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n))
{-# inline length #-}
length' :: forall v n s a. ()
=> MVector v n s a -> Proxy n
length' :: forall (v :: * -> * -> *) (n :: Nat) s a.
MVector v n s a -> Proxy n
length' MVector v n s a
_ = Proxy n
forall {k} (t :: k). Proxy t
Proxy
{-# inline length' #-}
null :: forall v n s a. KnownNat n
=> MVector v n s a -> Bool
null :: forall (v :: * -> * -> *) (n :: Nat) s a.
KnownNat n =>
MVector v n s a -> Bool
null MVector v n s a
_ = Maybe (n :~: 0) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (n :~: 0) -> Bool) -> Maybe (n :~: 0) -> Bool
forall a b. (a -> b) -> a -> b
$ forall (t :: Nat). Proxy t
forall {k} (t :: k). Proxy t
Proxy @n Proxy n -> Proxy 0 -> Maybe (n :~: 0)
forall (a :: Nat) (b :: Nat) (proxy1 :: Nat -> *)
(proxy2 :: Nat -> *).
(KnownNat a, KnownNat b) =>
proxy1 a -> proxy2 b -> Maybe (a :~: b)
`sameNat` forall (t :: Nat). Proxy t
forall {k} (t :: k). Proxy t
Proxy @0
{-# inline null #-}
slice :: forall v i n k s a p. (KnownNat i, KnownNat n, VGM.MVector v a)
=> p i
-> MVector v (i+n+k) s a
-> MVector v n s a
slice :: forall (v :: * -> * -> *) (i :: Nat) (n :: Nat) (k :: Nat) s a
(p :: Nat -> *).
(KnownNat i, KnownNat n, MVector v a) =>
p i -> MVector v ((i + n) + k) s a -> MVector v n s a
slice p i
start (MVector v s a
v) = v s a -> MVector v n s a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (Int -> Int -> v s a -> v s a
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
VGM.unsafeSlice Int
i Int
n v s a
v)
where i :: Int
i = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (p i -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal p i
start)
n :: Int
n = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n))
{-# inline slice #-}
slice' :: forall v i n k s a p
. (KnownNat i, KnownNat n, VGM.MVector v a)
=> p i
-> p n
-> MVector v (i+n+k) s a
-> MVector v n s a
slice' :: forall (v :: * -> * -> *) (i :: Nat) (n :: Nat) (k :: Nat) s a
(p :: Nat -> *).
(KnownNat i, KnownNat n, MVector v a) =>
p i -> p n -> MVector v ((i + n) + k) s a -> MVector v n s a
slice' p i
start p n
_ = p i -> MVector v ((i + n) + k) s a -> MVector v n s a
forall (v :: * -> * -> *) (i :: Nat) (n :: Nat) (k :: Nat) s a
(p :: Nat -> *).
(KnownNat i, KnownNat n, MVector v a) =>
p i -> MVector v ((i + n) + k) s a -> MVector v n s a
slice p i
start
{-# inline slice' #-}
init :: forall v n s a. VGM.MVector v a
=> MVector v (n+1) s a -> MVector v n s a
init :: forall (v :: * -> * -> *) (n :: Nat) s a.
MVector v a =>
MVector v (n + 1) s a -> MVector v n s a
init (MVector v s a
v) = v s a -> MVector v n s a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (v s a -> v s a
forall (v :: * -> * -> *) a s. MVector v a => v s a -> v s a
VGM.unsafeInit v s a
v)
{-# inline init #-}
tail :: forall v n s a. VGM.MVector v a
=> MVector v (1+n) s a -> MVector v n s a
tail :: forall (v :: * -> * -> *) (n :: Nat) s a.
MVector v a =>
MVector v (1 + n) s a -> MVector v n s a
tail (MVector v s a
v) = v s a -> MVector v n s a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (v s a -> v s a
forall (v :: * -> * -> *) a s. MVector v a => v s a -> v s a
VGM.unsafeTail v s a
v)
{-# inline tail #-}
take :: forall v n k s a. (KnownNat n, VGM.MVector v a)
=> MVector v (n+k) s a -> MVector v n s a
take :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) s a.
(KnownNat n, MVector v a) =>
MVector v (n + k) s a -> MVector v n s a
take (MVector v s a
v) = v s a -> MVector v n s a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (Int -> v s a -> v s a
forall (v :: * -> * -> *) a s. MVector v a => Int -> v s a -> v s a
VGM.unsafeTake Int
i v s a
v)
where i :: Int
i = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n))
{-# inline take #-}
take' :: forall v n k s a p. (KnownNat n, VGM.MVector v a)
=> p n -> MVector v (n+k) s a -> MVector v n s a
take' :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) s a
(p :: Nat -> *).
(KnownNat n, MVector v a) =>
p n -> MVector v (n + k) s a -> MVector v n s a
take' p n
_ = MVector v (n + k) s a -> MVector v n s a
forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) s a.
(KnownNat n, MVector v a) =>
MVector v (n + k) s a -> MVector v n s a
take
{-# inline take' #-}
drop :: forall v n k s a. (KnownNat n, VGM.MVector v a)
=> MVector v (n+k) s a -> MVector v k s a
drop :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) s a.
(KnownNat n, MVector v a) =>
MVector v (n + k) s a -> MVector v k s a
drop (MVector v s a
v) = v s a -> MVector v k s a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (Int -> v s a -> v s a
forall (v :: * -> * -> *) a s. MVector v a => Int -> v s a -> v s a
VGM.unsafeDrop Int
i v s a
v)
where i :: Int
i = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n))
{-# inline drop #-}
drop' :: forall v n k s a p. (KnownNat n, VGM.MVector v a)
=> p n -> MVector v (n+k) s a -> MVector v k s a
drop' :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) s a
(p :: Nat -> *).
(KnownNat n, MVector v a) =>
p n -> MVector v (n + k) s a -> MVector v k s a
drop' p n
_ = MVector v (n + k) s a -> MVector v k s a
forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) s a.
(KnownNat n, MVector v a) =>
MVector v (n + k) s a -> MVector v k s a
drop
{-# inline drop' #-}
splitAt :: forall v n m s a. (KnownNat n, VGM.MVector v a)
=> MVector v (n+m) s a -> (MVector v n s a, MVector v m s a)
splitAt :: forall (v :: * -> * -> *) (n :: Nat) (m :: Nat) s a.
(KnownNat n, MVector v a) =>
MVector v (n + m) s a -> (MVector v n s a, MVector v m s a)
splitAt (MVector v s a
v) = (v s a -> MVector v n s a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector v s a
a, v s a -> MVector v m s a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector v s a
b)
where i :: Int
i = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n))
(v s a
a, v s a
b) = Int -> v s a -> (v s a, v s a)
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> v s a -> (v s a, v s a)
VGM.splitAt Int
i v s a
v
{-# inline splitAt #-}
splitAt' :: forall v n m s a p. (KnownNat n, VGM.MVector v a)
=> p n -> MVector v (n+m) s a -> (MVector v n s a, MVector v m s a)
splitAt' :: forall (v :: * -> * -> *) (n :: Nat) (m :: Nat) s a
(p :: Nat -> *).
(KnownNat n, MVector v a) =>
p n -> MVector v (n + m) s a -> (MVector v n s a, MVector v m s a)
splitAt' p n
_ = MVector v (n + m) s a -> (MVector v n s a, MVector v m s a)
forall (v :: * -> * -> *) (n :: Nat) (m :: Nat) s a.
(KnownNat n, MVector v a) =>
MVector v (n + m) s a -> (MVector v n s a, MVector v m s a)
splitAt
{-# inline splitAt' #-}
overlaps :: forall v n k s a. VGM.MVector v a
=> MVector v n s a
-> MVector v k s a
-> Bool
overlaps :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) s a.
MVector v a =>
MVector v n s a -> MVector v k s a -> Bool
overlaps (MVector v s a
v) (MVector v s a
u) = v s a -> v s a -> Bool
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
VGM.overlaps v s a
v v s a
u
{-# inline overlaps #-}
new :: forall v n m a. (KnownNat n, PrimMonad m, VGM.MVector v a)
=> m (MVector v n (PrimState m) a)
new :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(KnownNat n, PrimMonad m, MVector v a) =>
m (MVector v n (PrimState m) a)
new = v (PrimState m) a -> MVector v n (PrimState m) a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (v (PrimState m) a -> MVector v n (PrimState m) a)
-> m (v (PrimState m) a) -> m (MVector v n (PrimState m) a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> m (v (PrimState m) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
Int -> m (v (PrimState m) a)
VGM.new (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)))
{-# inline new #-}
unsafeNew :: forall v n m a. (KnownNat n, PrimMonad m, VGM.MVector v a)
=> m (MVector v n (PrimState m) a)
unsafeNew :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(KnownNat n, PrimMonad m, MVector v a) =>
m (MVector v n (PrimState m) a)
unsafeNew = v (PrimState m) a -> MVector v n (PrimState m) a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (v (PrimState m) a -> MVector v n (PrimState m) a)
-> m (v (PrimState m) a) -> m (MVector v n (PrimState m) a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> m (v (PrimState m) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
Int -> m (v (PrimState m) a)
VGM.new (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)))
{-# inline unsafeNew #-}
replicate :: forall v n m a. (KnownNat n, PrimMonad m, VGM.MVector v a)
=> a -> m (MVector v n (PrimState m) a)
replicate :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(KnownNat n, PrimMonad m, MVector v a) =>
a -> m (MVector v n (PrimState m) a)
replicate = (v (PrimState m) a -> MVector v n (PrimState m) a)
-> m (v (PrimState m) a) -> m (MVector v n (PrimState m) a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap v (PrimState m) a -> MVector v n (PrimState m) a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (m (v (PrimState m) a) -> m (MVector v n (PrimState m) a))
-> (a -> m (v (PrimState m) a))
-> a
-> m (MVector v n (PrimState m) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> m (v (PrimState m) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
Int -> a -> m (v (PrimState m) a)
VGM.replicate (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)))
{-# inline replicate #-}
replicate' :: forall v n m a p. (KnownNat n, PrimMonad m, VGM.MVector v a)
=> p n -> a -> m (MVector v n (PrimState m) a)
replicate' :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a
(p :: Nat -> *).
(KnownNat n, PrimMonad m, MVector v a) =>
p n -> a -> m (MVector v n (PrimState m) a)
replicate' p n
_ = a -> m (MVector v n (PrimState m) a)
forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(KnownNat n, PrimMonad m, MVector v a) =>
a -> m (MVector v n (PrimState m) a)
replicate
{-# inline replicate' #-}
replicateM :: forall v n m a. (KnownNat n, PrimMonad m, VGM.MVector v a)
=> m a -> m (MVector v n (PrimState m) a)
replicateM :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(KnownNat n, PrimMonad m, MVector v a) =>
m a -> m (MVector v n (PrimState m) a)
replicateM = (v (PrimState m) a -> MVector v n (PrimState m) a)
-> m (v (PrimState m) a) -> m (MVector v n (PrimState m) a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap v (PrimState m) a -> MVector v n (PrimState m) a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (m (v (PrimState m) a) -> m (MVector v n (PrimState m) a))
-> (m a -> m (v (PrimState m) a))
-> m a
-> m (MVector v n (PrimState m) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> m a -> m (v (PrimState m) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
Int -> m a -> m (v (PrimState m) a)
VGM.replicateM (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)))
{-# inline replicateM #-}
replicateM' :: forall v n m a p. (KnownNat n, PrimMonad m, VGM.MVector v a)
=> p n -> m a -> m (MVector v n (PrimState m) a)
replicateM' :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a
(p :: Nat -> *).
(KnownNat n, PrimMonad m, MVector v a) =>
p n -> m a -> m (MVector v n (PrimState m) a)
replicateM' p n
_ = m a -> m (MVector v n (PrimState m) a)
forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(KnownNat n, PrimMonad m, MVector v a) =>
m a -> m (MVector v n (PrimState m) a)
replicateM
{-# inline replicateM' #-}
clone :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> m (MVector v n (PrimState m) a)
clone :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> m (MVector v n (PrimState m) a)
clone (MVector v (PrimState m) a
v) = v (PrimState m) a -> MVector v n (PrimState m) a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (v (PrimState m) a -> MVector v n (PrimState m) a)
-> m (v (PrimState m) a) -> m (MVector v n (PrimState m) a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> v (PrimState m) a -> m (v (PrimState m) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> m (v (PrimState m) a)
VGM.clone v (PrimState m) a
v
{-# inline clone #-}
grow :: forall v n k m a p. (KnownNat k, PrimMonad m, VGM.MVector v a)
=> p k -> MVector v n (PrimState m) a -> m (MVector v (n + k) (PrimState m) a)
grow :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) (m :: * -> *) a
(p :: Nat -> *).
(KnownNat k, PrimMonad m, MVector v a) =>
p k
-> MVector v n (PrimState m) a
-> m (MVector v (n + k) (PrimState m) a)
grow p k
_ (MVector v (PrimState m) a
v) = v (PrimState m) a -> MVector v (n + k) (PrimState m) a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (v (PrimState m) a -> MVector v (n + k) (PrimState m) a)
-> m (v (PrimState m) a) -> m (MVector v (n + k) (PrimState m) a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> v (PrimState m) a -> Int -> m (v (PrimState m) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> m (v (PrimState m) a)
VGM.unsafeGrow v (PrimState m) a
v (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Proxy k -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy k
forall {k} (t :: k). Proxy t
Proxy :: Proxy k)))
{-# inline grow #-}
growFront :: forall v n k m a p. (KnownNat k, PrimMonad m, VGM.MVector v a)
=> p k -> MVector v n (PrimState m) a -> m (MVector v (n + k) (PrimState m) a)
growFront :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) (m :: * -> *) a
(p :: Nat -> *).
(KnownNat k, PrimMonad m, MVector v a) =>
p k
-> MVector v n (PrimState m) a
-> m (MVector v (n + k) (PrimState m) a)
growFront p k
_ (MVector v (PrimState m) a
v) = v (PrimState m) a -> MVector v (n + k) (PrimState m) a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector (v (PrimState m) a -> MVector v (n + k) (PrimState m) a)
-> m (v (PrimState m) a) -> m (MVector v (n + k) (PrimState m) a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
v (PrimState m) a -> Int -> m (v (PrimState m) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> m (v (PrimState m) a)
VGM.unsafeGrowFront v (PrimState m) a
v (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Proxy k -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy k
forall {k} (t :: k). Proxy t
Proxy :: Proxy k)))
{-# inline growFront #-}
clear :: (PrimMonad m, VGM.MVector v a) => MVector v n (PrimState m) a -> m ()
clear :: forall (m :: * -> *) (v :: * -> * -> *) a (n :: Nat).
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> m ()
clear (MVector v (PrimState m) a
v) = v (PrimState m) a -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> m ()
VGM.clear v (PrimState m) a
v
{-# inline clear #-}
read :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Finite n -> m a
read :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> Finite n -> m a
read (MVector v (PrimState m) a
v) (Finite Integer
i) = v (PrimState m) a
v v (PrimState m) a -> Int -> m a
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> m a
`VGM.unsafeRead` Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i
{-# inline read #-}
read' :: forall v n k a m p. (KnownNat k, PrimMonad m, VGM.MVector v a)
=> MVector v (n+k+1) (PrimState m) a -> p k -> m a
read' :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) a (m :: * -> *)
(p :: Nat -> *).
(KnownNat k, PrimMonad m, MVector v a) =>
MVector v ((n + k) + 1) (PrimState m) a -> p k -> m a
read' (MVector v (PrimState m) a
v) p k
p = v (PrimState m) a
v v (PrimState m) a -> Int -> m a
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> m a
`VGM.unsafeRead` Integer -> Int
forall a. Num a => Integer -> a
fromInteger (p k -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal p k
p)
{-# inline read' #-}
unsafeRead :: forall v n a m. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Int -> m a
unsafeRead :: forall (v :: * -> * -> *) (n :: Nat) a (m :: * -> *).
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> Int -> m a
unsafeRead (MVector v (PrimState m) a
v) Int
i = v (PrimState m) a
v v (PrimState m) a -> Int -> m a
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> m a
`VGM.unsafeRead` Int
i
{-# inline unsafeRead #-}
write :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Finite n -> a -> m ()
write :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> Finite n -> a -> m ()
write (MVector v (PrimState m) a
v) (Finite Integer
i) = v (PrimState m) a -> Int -> a -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m ()
VGM.unsafeWrite v (PrimState m) a
v (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i)
{-# inline write #-}
write' :: forall v n k a m p. (KnownNat k, PrimMonad m, VGM.MVector v a)
=> MVector v (n+k+1) (PrimState m) a -> p k -> a -> m ()
write' :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) a (m :: * -> *)
(p :: Nat -> *).
(KnownNat k, PrimMonad m, MVector v a) =>
MVector v ((n + k) + 1) (PrimState m) a -> p k -> a -> m ()
write' (MVector v (PrimState m) a
v) p k
p = v (PrimState m) a -> Int -> a -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m ()
VGM.unsafeWrite v (PrimState m) a
v (Integer -> Int
forall a. Num a => Integer -> a
fromInteger (p k -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal p k
p))
{-# inline write' #-}
unsafeWrite :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Int -> a -> m ()
unsafeWrite :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> Int -> a -> m ()
unsafeWrite (MVector v (PrimState m) a
v) = v (PrimState m) a -> Int -> a -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m ()
VGM.unsafeWrite v (PrimState m) a
v
{-# inline unsafeWrite #-}
modify :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> (a -> a) -> Finite n -> m ()
modify :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> (a -> a) -> Finite n -> m ()
modify (MVector v (PrimState m) a
v) a -> a
f (Finite Integer
i) = v (PrimState m) a -> (a -> a) -> Int -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> (a -> a) -> Int -> m ()
VGM.unsafeModify v (PrimState m) a
v a -> a
f (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i)
{-# inline modify #-}
modify' :: forall v n k a m p. (KnownNat k, PrimMonad m, VGM.MVector v a)
=> MVector v (n+k+1) (PrimState m) a -> (a -> a) -> p k -> m ()
modify' :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) a (m :: * -> *)
(p :: Nat -> *).
(KnownNat k, PrimMonad m, MVector v a) =>
MVector v ((n + k) + 1) (PrimState m) a -> (a -> a) -> p k -> m ()
modify' (MVector v (PrimState m) a
v) a -> a
f p k
p = v (PrimState m) a -> (a -> a) -> Int -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> (a -> a) -> Int -> m ()
VGM.unsafeModify v (PrimState m) a
v a -> a
f (Integer -> Int
forall a. Num a => Integer -> a
fromInteger (p k -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal p k
p))
{-# inline modify' #-}
unsafeModify :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> (a -> a) -> Int -> m ()
unsafeModify :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> (a -> a) -> Int -> m ()
unsafeModify (MVector v (PrimState m) a
v) = v (PrimState m) a -> (a -> a) -> Int -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> (a -> a) -> Int -> m ()
VGM.unsafeModify v (PrimState m) a
v
{-# inline unsafeModify #-}
swap :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Finite n -> Finite n -> m ()
swap :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> Finite n -> Finite n -> m ()
swap (MVector v (PrimState m) a
v) (Finite Integer
i) (Finite Integer
j) = v (PrimState m) a -> Int -> Int -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> Int -> m ()
VGM.unsafeSwap v (PrimState m) a
v (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i) (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
j)
{-# inline swap #-}
unsafeSwap :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Int -> Int -> m ()
unsafeSwap :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> Int -> Int -> m ()
unsafeSwap (MVector v (PrimState m) a
v) = v (PrimState m) a -> Int -> Int -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> Int -> m ()
VGM.unsafeSwap v (PrimState m) a
v
{-# inline unsafeSwap #-}
exchange :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Finite n -> a -> m a
exchange :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> Finite n -> a -> m a
exchange (MVector v (PrimState m) a
v) (Finite Integer
i) = v (PrimState m) a -> Int -> a -> m a
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m a
VGM.unsafeExchange v (PrimState m) a
v (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i)
{-# inline exchange #-}
exchange' :: forall v n k a m p. (KnownNat k, PrimMonad m, VGM.MVector v a)
=> MVector v (n+k+1) (PrimState m) a -> p k -> a -> m a
exchange' :: forall (v :: * -> * -> *) (n :: Nat) (k :: Nat) a (m :: * -> *)
(p :: Nat -> *).
(KnownNat k, PrimMonad m, MVector v a) =>
MVector v ((n + k) + 1) (PrimState m) a -> p k -> a -> m a
exchange' (MVector v (PrimState m) a
v) p k
p = v (PrimState m) a -> Int -> a -> m a
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m a
VGM.unsafeExchange v (PrimState m) a
v (Integer -> Int
forall a. Num a => Integer -> a
fromInteger (p k -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal p k
p))
{-# inline exchange' #-}
unsafeExchange :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Int -> a -> m a
unsafeExchange :: forall (v :: * -> * -> *) (n :: Nat) (m :: * -> *) a.
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> Int -> a -> m a
unsafeExchange (MVector v (PrimState m) a
v) = v (PrimState m) a -> Int -> a -> m a
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m a
VGM.unsafeExchange v (PrimState m) a
v
{-# inline unsafeExchange #-}
nextPermutation :: forall v n e m. (Ord e, PrimMonad m, VGM.MVector v e)
=> MVector v n (PrimState m) e -> m Bool
nextPermutation :: forall (v :: * -> * -> *) (n :: Nat) e (m :: * -> *).
(Ord e, PrimMonad m, MVector v e) =>
MVector v n (PrimState m) e -> m Bool
nextPermutation (MVector v (PrimState m) e
v) = v (PrimState m) e -> m Bool
forall (m :: * -> *) e (v :: * -> * -> *).
(PrimMonad m, Ord e, MVector v e) =>
v (PrimState m) e -> m Bool
VGM.nextPermutation v (PrimState m) e
v
{-# inline nextPermutation #-}
set :: (PrimMonad m, VGM.MVector v a) => MVector v n (PrimState m) a -> a -> m ()
set :: forall (m :: * -> *) (v :: * -> * -> *) a (n :: Nat).
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> a -> m ()
set (MVector v (PrimState m) a
v) = v (PrimState m) a -> a -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> a -> m ()
VGM.set v (PrimState m) a
v
{-# inline set #-}
copy :: (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a
-> MVector v n (PrimState m) a
-> m ()
copy :: forall (m :: * -> *) (v :: * -> * -> *) a (n :: Nat).
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> MVector v n (PrimState m) a -> m ()
copy (MVector v (PrimState m) a
v) (MVector v (PrimState m) a
u)
| v (PrimState m) a
v v (PrimState m) a -> v (PrimState m) a -> Bool
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
`VGM.overlaps` v (PrimState m) a
u = [Char] -> m ()
forall a. HasCallStack => [Char] -> a
error [Char]
"copy: overlapping vectors"
| Bool
otherwise = v (PrimState m) a -> v (PrimState m) a -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
VGM.unsafeCopy v (PrimState m) a
v v (PrimState m) a
u
{-# inline copy #-}
unsafeCopy :: (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a
-> MVector v n (PrimState m) a
-> m ()
unsafeCopy :: forall (m :: * -> *) (v :: * -> * -> *) a (n :: Nat).
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> MVector v n (PrimState m) a -> m ()
unsafeCopy (MVector v (PrimState m) a
v) (MVector v (PrimState m) a
u) = v (PrimState m) a -> v (PrimState m) a -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
VGM.unsafeCopy v (PrimState m) a
v v (PrimState m) a
u
{-# inline unsafeCopy #-}
move :: (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a
-> MVector v n (PrimState m) a
-> m ()
move :: forall (m :: * -> *) (v :: * -> * -> *) a (n :: Nat).
(PrimMonad m, MVector v a) =>
MVector v n (PrimState m) a -> MVector v n (PrimState m) a -> m ()
move (MVector v (PrimState m) a
v) (MVector v (PrimState m) a
u) = v (PrimState m) a -> v (PrimState m) a -> m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
VGM.unsafeMove v (PrimState m) a
v v (PrimState m) a
u
{-# inline move #-}
toSized :: forall v n s a. (VGM.MVector v a, KnownNat n)
=> v s a -> Maybe (MVector v n s a)
toSized :: forall (v :: * -> * -> *) (n :: Nat) s a.
(MVector v a, KnownNat n) =>
v s a -> Maybe (MVector v n s a)
toSized v s a
v
| Integer
n' Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (v s a -> Int
forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
VGM.length v s a
v) = MVector v n s a -> Maybe (MVector v n s a)
forall a. a -> Maybe a
Just (v s a -> MVector v n s a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector v s a
v)
| Bool
otherwise = Maybe (MVector v n s a)
forall a. Maybe a
Nothing
where n' :: Integer
n' = Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
{-# inline toSized #-}
withSized :: forall v s a r. VGM.MVector v a
=> v s a -> (forall n. KnownNat n => MVector v n s a -> r) -> r
withSized :: forall (v :: * -> * -> *) s a r.
MVector v a =>
v s a
-> (forall (n :: Nat). KnownNat n => MVector v n s a -> r) -> r
withSized v s a
v forall (n :: Nat). KnownNat n => MVector v n s a -> r
f = case Integer -> Maybe SomeNat
someNatVal (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (v s a -> Int
forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
VGM.length v s a
v)) of
Just (SomeNat (Proxy n
Proxy :: Proxy n)) -> MVector v n s a -> r
forall (n :: Nat). KnownNat n => MVector v n s a -> r
f (v s a -> MVector v n s a
forall (v :: * -> * -> *) (n :: Nat) s a. v s a -> MVector v n s a
MVector v s a
v :: MVector v n s a)
Maybe SomeNat
Nothing -> [Char] -> r
forall a. HasCallStack => [Char] -> a
error [Char]
"withSized: VGM.length returned negative length."
fromSized :: MVector v n s a -> v s a
fromSized :: forall (v :: * -> * -> *) (n :: Nat) s a. MVector v n s a -> v s a
fromSized (MVector v s a
v) = v s a
v
{-# inline fromSized #-}