{-# LANGUAGE Trustworthy, MagicHash, UnboxedTuples, BangPatterns, TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, RoleAnnotations #-}
module SDP.Prim.SArray
(
module SDP.IndexedM,
module SDP.SortM,
module SDP.Sort,
MIOArray# (..), IOArray#, STArray#, SArray#,
fromSArray#, fromSTArray#,
unpackSArray#, offsetSArray#, unpackSTArray#, offsetSTArray#,
packSArray#, packSTArray#,
coerceSArray#, coerceSTArray#
)
where
import Prelude ()
import SDP.SafePrelude
import SDP.IndexedM
import SDP.SortM
import SDP.Sort
import SDP.Scan
import SDP.SortM.Tim
import qualified GHC.Exts as E
import GHC.Exts
(
Array#, MutableArray#, State#, Int#,
newArray#, indexArray#, readArray#, writeArray#,
thawArray#, unsafeThawArray#, freezeArray#, unsafeFreezeArray#,
copyArray#, copyMutableArray#, cloneArray#, cloneMutableArray#,
sameMutableArray#, (+#), (-#), (==#)
)
import GHC.Types
import GHC.ST ( ST (..), STRep )
import Data.Default.Class
import Data.Typeable
import Data.Coerce
import Data.String
import Data.Proxy
import Text.Read
import Foreign ( Ptr, Storable, callocArray, peekElemOff, pokeElemOff )
import Control.Exception.SDP
default ()
data SArray# e = SArray#
{-# UNPACK #-} !Int
{-# UNPACK #-} !Int
!(Array# e)
deriving ( Typeable )
type role SArray# representational
instance (Eq e) => Eq (SArray# e) where == :: SArray# e -> SArray# e -> Bool
(==) = SArray# e -> SArray# e -> Bool
forall (f :: * -> *) a. (Eq1 f, Eq a) => f a -> f a -> Bool
eq1
instance Eq1 SArray#
where
liftEq :: (a -> b -> Bool) -> SArray# a -> SArray# b -> Bool
liftEq a -> b -> Bool
eq xs :: SArray# a
xs@(SArray# Int
c1 Int
_ Array# a
_) ys :: SArray# b
ys@(SArray# Int
c2 Int
_ Array# b
_) =
let eq' :: Int -> Bool
eq' Int
i = Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
c1 Bool -> Bool -> Bool
|| a -> b -> Bool
eq (SArray# a
xs SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# b
ys SArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^ Int
i) Bool -> Bool -> Bool
&& Int -> Bool
eq' (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
in Int
c1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
c2 Bool -> Bool -> Bool
&& Int -> Bool
eq' Int
0
instance (Ord e) => Ord (SArray# e) where compare :: SArray# e -> SArray# e -> Ordering
compare = SArray# e -> SArray# e -> Ordering
forall (f :: * -> *) a. (Ord1 f, Ord a) => f a -> f a -> Ordering
compare1
instance Ord1 SArray#
where
liftCompare :: (a -> b -> Ordering) -> SArray# a -> SArray# b -> Ordering
liftCompare a -> b -> Ordering
f xs :: SArray# a
xs@(SArray# Int
c1 Int
_ Array# a
_) ys :: SArray# b
ys@(SArray# Int
c2 Int
_ Array# b
_) =
let f' :: Int -> Ordering
f' Int
i = Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
c1Int -> Int -> Int
forall a. Ord a => a -> a -> a
`min`Int
c2) Bool -> Ordering -> Ordering -> Ordering
forall a. Bool -> a -> a -> a
? Int
c1 Compare Int
forall o. Ord o => Compare o
<=> Int
c2 (Ordering -> Ordering) -> Ordering -> Ordering
forall a b. (a -> b) -> a -> b
$ (SArray# a
xsSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) a -> b -> Ordering
`f` (SArray# b
ysSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i) Ordering -> Ordering -> Ordering
forall a. Semigroup a => a -> a -> a
<> Int -> Ordering
f' (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
in Int -> Ordering
f' Int
0
instance (Show e) => Show (SArray# e) where showsPrec :: Int -> SArray# e -> ShowS
showsPrec Int
p = Int -> [e] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p ([e] -> ShowS) -> (SArray# e -> [e]) -> SArray# e -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> [e]
forall l e. Linear l e => l -> [e]
listL
instance (Read e) => Read (SArray# e) where readPrec :: ReadPrec (SArray# e)
readPrec = [e] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList ([e] -> SArray# e) -> ReadPrec [e] -> ReadPrec (SArray# e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadPrec [e]
forall a. Read a => ReadPrec a
readPrec
instance IsString (SArray# Char) where fromString :: String -> SArray# Char
fromString = String -> SArray# Char
forall l e. Linear l e => [e] -> l
fromList
instance E.IsList (SArray# e)
where
type Item (SArray# e) = e
fromListN :: Int -> [Item (SArray# e)] -> SArray# e
fromListN = Int -> [Item (SArray# e)] -> SArray# e
forall l e. Linear l e => Int -> [e] -> l
fromListN
fromList :: [Item (SArray# e)] -> SArray# e
fromList = [Item (SArray# e)] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList
toList :: SArray# e -> [Item (SArray# e)]
toList = SArray# e -> [Item (SArray# e)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
instance Nullable (SArray# e)
where
lzero :: SArray# e
lzero = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
0 (String -> e
forall a. String -> a
unreachEx String
"lzero") ST s (STArray# s e)
-> (STArray# s e -> ST s (SArray# e)) -> ST s (SArray# e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done
isNull :: SArray# e -> Bool
isNull = \ (SArray# Int
c Int
_ Array# e
_) -> Int
c Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
instance Semigroup (SArray# e) where <> :: SArray# e -> SArray# e -> SArray# e
(<>) = SArray# e -> SArray# e -> SArray# e
forall l e. Linear l e => l -> l -> l
(++)
instance Monoid (SArray# e) where mempty :: SArray# e
mempty = SArray# e
forall e. Nullable e => e
Z
instance Default (SArray# e) where def :: SArray# e
def = SArray# e
forall e. Nullable e => e
Z
instance Estimate (SArray# e)
where
<==> :: Compare (SArray# e)
(<==>) = Compare Int -> (SArray# e -> Int) -> Compare (SArray# e)
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Compare Int
forall o. Ord o => Compare o
(<=>) SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.<=. :: SArray# e -> SArray# e -> Bool
(.<=.) = (Int -> Int -> Bool)
-> (SArray# e -> Int) -> SArray# e -> SArray# e -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<=) SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.>=. :: SArray# e -> SArray# e -> Bool
(.>=.) = (Int -> Int -> Bool)
-> (SArray# e -> Int) -> SArray# e -> SArray# e -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=) SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.>. :: SArray# e -> SArray# e -> Bool
(.>.) = (Int -> Int -> Bool)
-> (SArray# e -> Int) -> SArray# e -> SArray# e -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>) SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.<. :: SArray# e -> SArray# e -> Bool
(.<.) = (Int -> Int -> Bool)
-> (SArray# e -> Int) -> SArray# e -> SArray# e -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
<.=> :: SArray# e -> Int -> Ordering
(<.=>) = Compare Int
forall o. Ord o => Compare o
(<=>) Compare Int -> (SArray# e -> Int) -> SArray# e -> Int -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.>= :: SArray# e -> Int -> Bool
(.>=) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=) (Int -> Int -> Bool)
-> (SArray# e -> Int) -> SArray# e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.<= :: SArray# e -> Int -> Bool
(.<=) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<=) (Int -> Int -> Bool)
-> (SArray# e -> Int) -> SArray# e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.> :: SArray# e -> Int -> Bool
(.>) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>) (Int -> Int -> Bool)
-> (SArray# e -> Int) -> SArray# e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.< :: SArray# e -> Int -> Bool
(.<) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) (Int -> Int -> Bool)
-> (SArray# e -> Int) -> SArray# e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
instance Functor SArray#
where
fmap :: (a -> b) -> SArray# a -> SArray# b
fmap a -> b
f arr :: SArray# a
arr@(SArray# n :: Int
n@(I# Int#
n#) Int
_ Array# a
_) = (forall s. ST s (SArray# b)) -> SArray# b
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# b)) -> SArray# b)
-> (forall s. ST s (SArray# b)) -> SArray# b
forall a b. (a -> b) -> a -> b
$ STRep s (SArray# b) -> ST s (SArray# b)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# b) -> ST s (SArray# b))
-> STRep s (SArray# b) -> ST s (SArray# b)
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# ->
case Int# -> b -> State# s -> (# State# s, MutableArray# s b #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# (String -> b
forall a. String -> a
unreachEx String
"fmap") State# s
s1# of
(# State# s
s2#, MutableArray# s b
marr# #) ->
let go :: Int -> STRep s (SArray# b)
go i :: Int
i@(I# Int#
i#) State# s
s3# = if Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n
then case MutableArray# s b -> State# s -> (# State# s, Array# b #)
forall d a.
MutableArray# d a -> State# d -> (# State# d, Array# a #)
unsafeFreezeArray# MutableArray# s b
marr# State# s
s3# of (# State# s
s4#, Array# b
arr# #) -> (# State# s
s4#, Int -> Int -> Array# b -> SArray# b
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
n Int
0 Array# b
arr# #)
else case MutableArray# s b -> Int# -> b -> State# s -> State# s
forall d a. MutableArray# d a -> Int# -> a -> State# d -> State# d
writeArray# MutableArray# s b
marr# Int#
i# (a -> b
f (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ SArray# a
arr SArray# a -> Int -> a
forall map key e. Map map key e => map -> key -> e
! Int
i) State# s
s3# of State# s
s5# -> Int -> STRep s (SArray# b)
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) State# s
s5#
in Int -> STRep s (SArray# b)
go Int
0 State# s
s2#
instance Zip SArray#
where
all2 :: (a -> b -> Bool) -> SArray# a -> SArray# b -> Bool
all2 a -> b -> Bool
f SArray# a
as SArray# b
bs = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs])
where
apply :: Int -> Bool
apply Int
i = a -> b -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
True
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
&& Int -> Bool
go Int
i'
all3 :: (a -> b -> c -> Bool)
-> SArray# a -> SArray# b -> SArray# c -> Bool
all3 a -> b -> c -> Bool
f SArray# a
as SArray# b
bs SArray# c
cs = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs])
where
apply :: Int -> Bool
apply Int
i = a -> b -> c -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# c
csSArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
True
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
&& Int -> Bool
go Int
i'
all4 :: (a -> b -> c -> d -> Bool)
-> SArray# a -> SArray# b -> SArray# c -> SArray# d -> Bool
all4 a -> b -> c -> d -> Bool
f SArray# a
as SArray# b
bs SArray# c
cs SArray# d
ds = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs, SArray# d -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# d
ds])
where
apply :: Int -> Bool
apply Int
i = a -> b -> c -> d -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# c
csSArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# d
dsSArray# d -> Int -> d
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
True
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
&& Int -> Bool
go Int
i'
all5 :: (a -> b -> c -> d -> e -> Bool)
-> SArray# a
-> SArray# b
-> SArray# c
-> SArray# d
-> SArray# e
-> Bool
all5 a -> b -> c -> d -> e -> Bool
f SArray# a
as SArray# b
bs SArray# c
cs SArray# d
ds SArray# e
es = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs, SArray# d -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# d
ds, SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# e
es])
where
apply :: Int -> Bool
apply Int
i = a -> b -> c -> d -> e -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# c
csSArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# d
dsSArray# d -> Int -> d
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# e
esSArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
True
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
&& Int -> Bool
go Int
i'
all6 :: (a -> b -> c -> d -> e -> f -> Bool)
-> SArray# a
-> SArray# b
-> SArray# c
-> SArray# d
-> SArray# e
-> SArray# f
-> Bool
all6 a -> b -> c -> d -> e -> f -> Bool
f SArray# a
as SArray# b
bs SArray# c
cs SArray# d
ds SArray# e
es SArray# f
fs = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs, SArray# d -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# d
ds, SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# e
es, SArray# f -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# f
fs])
where
apply :: Int -> Bool
apply Int
i = a -> b -> c -> d -> e -> f -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# c
csSArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# d
dsSArray# d -> Int -> d
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# e
esSArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# f
fsSArray# f -> Int -> f
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
True
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
&& Int -> Bool
go Int
i'
any2 :: (a -> b -> Bool) -> SArray# a -> SArray# b -> Bool
any2 a -> b -> Bool
f SArray# a
as SArray# b
bs = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs])
where
apply :: Int -> Bool
apply Int
i = a -> b -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
False
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
|| Int -> Bool
go Int
i'
any3 :: (a -> b -> c -> Bool)
-> SArray# a -> SArray# b -> SArray# c -> Bool
any3 a -> b -> c -> Bool
f SArray# a
as SArray# b
bs SArray# c
cs = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs])
where
apply :: Int -> Bool
apply Int
i = a -> b -> c -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# c
csSArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
False
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
|| Int -> Bool
go Int
i'
any4 :: (a -> b -> c -> d -> Bool)
-> SArray# a -> SArray# b -> SArray# c -> SArray# d -> Bool
any4 a -> b -> c -> d -> Bool
f SArray# a
as SArray# b
bs SArray# c
cs SArray# d
ds = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs, SArray# d -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# d
ds])
where
apply :: Int -> Bool
apply Int
i = a -> b -> c -> d -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# c
csSArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# d
dsSArray# d -> Int -> d
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
False
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
|| Int -> Bool
go Int
i'
any5 :: (a -> b -> c -> d -> e -> Bool)
-> SArray# a
-> SArray# b
-> SArray# c
-> SArray# d
-> SArray# e
-> Bool
any5 a -> b -> c -> d -> e -> Bool
f SArray# a
as SArray# b
bs SArray# c
cs SArray# d
ds SArray# e
es = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs, SArray# d -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# d
ds, SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# e
es])
where
apply :: Int -> Bool
apply Int
i = a -> b -> c -> d -> e -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# c
csSArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# d
dsSArray# d -> Int -> d
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# e
esSArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
False
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
|| Int -> Bool
go Int
i'
any6 :: (a -> b -> c -> d -> e -> f -> Bool)
-> SArray# a
-> SArray# b
-> SArray# c
-> SArray# d
-> SArray# e
-> SArray# f
-> Bool
any6 a -> b -> c -> d -> e -> f -> Bool
f SArray# a
as SArray# b
bs SArray# c
cs SArray# d
ds SArray# e
es SArray# f
fs = Int -> Bool
go ([Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs, SArray# d -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# d
ds, SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# e
es, SArray# f -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# f
fs])
where
apply :: Int -> Bool
apply Int
i = a -> b -> c -> d -> e -> f -> Bool
f (SArray# a
asSArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# b
bsSArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# c
csSArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# d
dsSArray# d -> Int -> d
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# e
esSArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^Int
i) (SArray# f
fsSArray# f -> Int -> f
forall l e. Linear l e => l -> Int -> e
!^Int
i)
go :: Int -> Bool
go Int
0 = Bool
False
go Int
i = let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 in Int -> Bool
apply Int
i' Bool -> Bool -> Bool
|| Int -> Bool
go Int
i'
zipWith :: (a -> b -> c) -> SArray# a -> SArray# b -> SArray# c
zipWith a -> b -> c
f SArray# a
as SArray# b
bs = Int -> [c] -> SArray# c
forall l e. Linear l e => Int -> [e] -> l
fromListN Int
sz ([c] -> SArray# c) -> [c] -> SArray# c
forall a b. (a -> b) -> a -> b
$ Int -> c
apply (Int -> c) -> [Int] -> [c]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> [Int]
forall i. Index i => (i, i) -> [i]
range (Int
0, Int
sz Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
where
apply :: Int -> c
apply Int
i = a -> b -> c
f (SArray# a
as SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# b
bs SArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
sz :: Int
sz = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs]
zipWith3 :: (a -> b -> c -> d)
-> SArray# a -> SArray# b -> SArray# c -> SArray# d
zipWith3 a -> b -> c -> d
f SArray# a
as SArray# b
bs SArray# c
cs = Int -> [d] -> SArray# d
forall l e. Linear l e => Int -> [e] -> l
fromListN Int
sz ([d] -> SArray# d) -> [d] -> SArray# d
forall a b. (a -> b) -> a -> b
$ Int -> d
apply (Int -> d) -> [Int] -> [d]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> [Int]
forall i. Index i => (i, i) -> [i]
range (Int
0, Int
sz Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
where
apply :: Int -> d
apply Int
i = a -> b -> c -> d
f (SArray# a
as SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# b
bs SArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# c
cs SArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
sz :: Int
sz = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs]
zipWith4 :: (a -> b -> c -> d -> e)
-> SArray# a -> SArray# b -> SArray# c -> SArray# d -> SArray# e
zipWith4 a -> b -> c -> d -> e
f SArray# a
as SArray# b
bs SArray# c
cs SArray# d
ds = Int -> [e] -> SArray# e
forall l e. Linear l e => Int -> [e] -> l
fromListN Int
sz ([e] -> SArray# e) -> [e] -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> e
apply (Int -> e) -> [Int] -> [e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> [Int]
forall i. Index i => (i, i) -> [i]
range (Int
0, Int
sz Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
where
apply :: Int -> e
apply Int
i = a -> b -> c -> d -> e
f (SArray# a
as SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# b
bs SArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# c
cs SArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# d
ds SArray# d -> Int -> d
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
sz :: Int
sz = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs, SArray# d -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# d
ds]
zipWith5 :: (a -> b -> c -> d -> e -> f)
-> SArray# a
-> SArray# b
-> SArray# c
-> SArray# d
-> SArray# e
-> SArray# f
zipWith5 a -> b -> c -> d -> e -> f
f SArray# a
as SArray# b
bs SArray# c
cs SArray# d
ds SArray# e
es = Int -> [f] -> SArray# f
forall l e. Linear l e => Int -> [e] -> l
fromListN Int
sz ([f] -> SArray# f) -> [f] -> SArray# f
forall a b. (a -> b) -> a -> b
$ Int -> f
apply (Int -> f) -> [Int] -> [f]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> [Int]
forall i. Index i => (i, i) -> [i]
range (Int
0, Int
sz Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
where
apply :: Int -> f
apply Int
i = a -> b -> c -> d -> e -> f
f (SArray# a
as SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# b
bs SArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# c
cs SArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# d
ds SArray# d -> Int -> d
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
sz :: Int
sz = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs, SArray# d -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# d
ds, SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# e
es]
zipWith6 :: (a -> b -> c -> d -> e -> f -> g)
-> SArray# a
-> SArray# b
-> SArray# c
-> SArray# d
-> SArray# e
-> SArray# f
-> SArray# g
zipWith6 a -> b -> c -> d -> e -> f -> g
f SArray# a
as SArray# b
bs SArray# c
cs SArray# d
ds SArray# e
es SArray# f
fs = Int -> [g] -> SArray# g
forall l e. Linear l e => Int -> [e] -> l
fromListN Int
sz ([g] -> SArray# g) -> [g] -> SArray# g
forall a b. (a -> b) -> a -> b
$ Int -> g
apply (Int -> g) -> [Int] -> [g]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> [Int]
forall i. Index i => (i, i) -> [i]
range (Int
0, Int
sz Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
where
apply :: Int -> g
apply Int
i = a -> b -> c -> d -> e -> f -> g
f (SArray# a
as SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# b
bs SArray# b -> Int -> b
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# c
cs SArray# c -> Int -> c
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# d
ds SArray# d -> Int -> d
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (SArray# f
fs SArray# f -> Int -> f
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
sz :: Int
sz = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
as, SArray# b -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# b
bs, SArray# c -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# c
cs, SArray# d -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# d
ds, SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# e
es, SArray# f -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# f
fs]
instance Applicative SArray#
where
pure :: a -> SArray# a
pure = a -> SArray# a
forall l e. Linear l e => e -> l
single
SArray# (a -> b)
fs <*> :: SArray# (a -> b) -> SArray# a -> SArray# b
<*> SArray# a
es = ((a -> b) -> SArray# b) -> SArray# (a -> b) -> SArray# b
forall l e (f :: * -> *) a.
(Linear l e, Foldable f) =>
(a -> l) -> f a -> l
concatMap ((a -> b) -> SArray# a -> SArray# b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SArray# a
es) SArray# (a -> b)
fs
instance Foldable SArray#
where
foldr :: (a -> b -> b) -> b -> SArray# a -> b
foldr a -> b -> b
f b
base = \ SArray# a
arr ->
let go :: Int -> b
go Int
i = SArray# a
arr SArray# a -> Int -> Bool
forall e. Estimate e => e -> Int -> Bool
.== Int
i Bool -> b -> b -> b
forall a. Bool -> a -> a -> a
? b
base (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ a -> b -> b
f (SArray# a
arr SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (Int -> b
go (Int -> b) -> Int -> b
forall a b. (a -> b) -> a -> b
$ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
in Int -> b
go Int
0
foldl :: (b -> a -> b) -> b -> SArray# a -> b
foldl b -> a -> b
f b
base = \ SArray# a
arr ->
let go :: Int -> b
go Int
i = -Int
1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> b -> b -> b
forall a. Bool -> a -> a -> a
? b
base (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ b -> a -> b
f (Int -> b
go (Int -> b) -> Int -> b
forall a b. (a -> b) -> a -> b
$ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (SArray# a
arr SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
in Int -> b
go (SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
arr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
foldr' :: (a -> b -> b) -> b -> SArray# a -> b
foldr' a -> b -> b
f b
base = \ SArray# a
arr ->
let go :: Int -> b -> b
go Int
i !b
a = -Int
1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> b -> b -> b
forall a. Bool -> a -> a -> a
? b
a (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ Int -> b -> b
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (a -> b -> b
f (SArray# a
arr SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i) b
a)
in Int -> b -> b
go (SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
arr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) b
base
foldl' :: (b -> a -> b) -> b -> SArray# a -> b
foldl' b -> a -> b
f b
base = \ SArray# a
arr ->
let go :: Int -> b -> b
go Int
i !b
a = SArray# a
arr SArray# a -> Int -> Bool
forall e. Estimate e => e -> Int -> Bool
.== Int
i Bool -> b -> b -> b
forall a. Bool -> a -> a -> a
? b
a (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ Int -> b -> b
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (b -> a -> b
f b
a (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ SArray# a
arr SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
in Int -> b -> b
go Int
0 b
base
foldr1 :: (a -> a -> a) -> SArray# a -> a
foldr1 a -> a -> a
f = \ SArray# a
arr ->
let go :: Int -> a
go Int
i = SArray# a
arr SArray# a -> Int -> Bool
forall e. Estimate e => e -> Int -> Bool
.== (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Bool -> a -> a -> a
forall a. Bool -> a -> a -> a
? a
e (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ a -> a -> a
f a
e (Int -> a
go (Int -> a) -> Int -> a
forall a b. (a -> b) -> a -> b
$ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) where e :: a
e = SArray# a
arr SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i
in SArray# a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null SArray# a
arr Bool -> a -> a -> a
forall a. Bool -> a -> a -> a
? String -> a
forall a. String -> a
pfailEx String
"foldr1" (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ Int -> a
go Int
0
foldl1 :: (a -> a -> a) -> SArray# a -> a
foldl1 a -> a -> a
f = \ SArray# a
arr ->
let go :: Int -> a
go Int
i = Int
0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> a -> a -> a
forall a. Bool -> a -> a -> a
? a
e (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ a -> a -> a
f (Int -> a
go (Int -> a) -> Int -> a
forall a b. (a -> b) -> a -> b
$ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
e where e :: a
e = SArray# a
arr SArray# a -> Int -> a
forall l e. Linear l e => l -> Int -> e
!^ Int
i
in SArray# a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null SArray# a
arr Bool -> a -> a -> a
forall a. Bool -> a -> a -> a
? String -> a
forall a. String -> a
pfailEx String
"foldl1" (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ Int -> a
go (SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# a
arr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
length :: SArray# a -> Int
length = SArray# a -> Int
forall b i. Bordered b i => b -> Int
sizeOf
null :: SArray# a -> Bool
null = SArray# a -> Bool
forall e. Nullable e => e -> Bool
isNull
instance Traversable SArray#
where
traverse :: (a -> f b) -> SArray# a -> f (SArray# b)
traverse a -> f b
f = ([b] -> SArray# b) -> f [b] -> f (SArray# b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [b] -> SArray# b
forall l e. Linear l e => [e] -> l
fromList (f [b] -> f (SArray# b))
-> (SArray# a -> f [b]) -> SArray# a -> f (SArray# b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f [b] -> f [b]) -> f [b] -> SArray# a -> f [b]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((b -> [b] -> [b]) -> f b -> f [b] -> f [b]
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (:) (f b -> f [b] -> f [b]) -> (a -> f b) -> a -> f [b] -> f [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f) ([b] -> f [b]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [])
instance Linear (SArray# e) e
where
replicate :: Int -> e -> SArray# e
replicate Int
n e
e = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
n e
e ST s (STArray# s e)
-> (STArray# s e -> ST s (SArray# e)) -> ST s (SArray# e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done
single :: e -> SArray# e
single e
e = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
1 e
e ST s (STArray# s e)
-> (STArray# s e -> ST s (SArray# e)) -> ST s (SArray# e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done
toHead :: e -> SArray# e -> SArray# e
toHead e
e (SArray# (I# Int#
c#) (I# Int#
o#) Array# e
arr#) = let n# :: Int#
n# = Int#
c# Int# -> Int# -> Int#
+# Int#
1# in (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ STRep s (SArray# e) -> ST s (SArray# e)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# e) -> ST s (SArray# e))
-> STRep s (SArray# e) -> ST s (SArray# e)
forall a b. (a -> b) -> a -> b
$
\ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# e
e State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
arr# Int#
o# MutableArray# s e
marr# Int#
1# Int#
c# State# s
s2# of
State# s
s3# -> case MutableArray# s e -> State# s -> (# State# s, Array# e #)
forall d a.
MutableArray# d a -> State# d -> (# State# d, Array# a #)
unsafeFreezeArray# MutableArray# s e
marr# State# s
s3# of
(# State# s
s4#, Array# e
res# #) -> (# State# s
s4#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int# -> Int
I# Int#
n#) Int
0 Array# e
res# #)
toLast :: SArray# e -> e -> SArray# e
toLast (SArray# (I# Int#
c#) (I# Int#
o#) Array# e
arr#) e
e = let n# :: Int#
n# = Int#
c# Int# -> Int# -> Int#
+# Int#
1# in (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ STRep s (SArray# e) -> ST s (SArray# e)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# e) -> ST s (SArray# e))
-> STRep s (SArray# e) -> ST s (SArray# e)
forall a b. (a -> b) -> a -> b
$
\ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# e
e State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
arr# Int#
o# MutableArray# s e
marr# Int#
0# Int#
c# State# s
s2# of
State# s
s3# -> case MutableArray# s e -> State# s -> (# State# s, Array# e #)
forall d a.
MutableArray# d a -> State# d -> (# State# d, Array# a #)
unsafeFreezeArray# MutableArray# s e
marr# State# s
s3# of
(# State# s
s4#, Array# e
res# #) -> (# State# s
s4#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int# -> Int
I# Int#
n#) Int
0 Array# e
res# #)
head :: SArray# e -> e
head SArray# e
es = SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
0
last :: SArray# e -> e
last es :: SArray# e
es@(SArray# Int
c Int
_ Array# e
_) = SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
init :: SArray# e -> SArray# e
init (SArray# Int
c Int
o Array# e
arr#) = Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int
o Array# e
arr#
tail :: SArray# e -> SArray# e
tail (SArray# Int
c Int
o Array# e
arr#) = Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Array# e
arr#
fromList :: [e] -> SArray# e
fromList = [e] -> SArray# e
forall l e (f :: * -> *). (Linear l e, Foldable f) => f e -> l
fromFoldable
fromListN :: Int -> [e] -> SArray# e
fromListN Int
n [e]
es = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> [e] -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> [e] -> m l
newLinearN Int
n [e]
es ST s (STArray# s e)
-> (STArray# s e -> ST s (SArray# e)) -> ST s (SArray# e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done
fromFoldable :: f e -> SArray# e
fromFoldable f e
es = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ f e -> ST s (STArray# s e)
forall (m :: * -> *) l e (f :: * -> *).
(LinearM m l e, Foldable f) =>
f e -> m l
fromFoldableM f e
es ST s (STArray# s e)
-> (STArray# s e -> ST s (SArray# e)) -> ST s (SArray# e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done
SArray# (I# Int#
n1#) (I# Int#
o1#) Array# e
arr1# ++ :: SArray# e -> SArray# e -> SArray# e
++ SArray# (I# Int#
n2#) (I# Int#
o2#) Array# e
arr2# =
(forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ STRep s (SArray# e) -> ST s (SArray# e)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# e) -> ST s (SArray# e))
-> STRep s (SArray# e) -> ST s (SArray# e)
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# (String -> e
forall a. String -> a
unreachEx String
"(++)") State# s
s1# of
(#State# s
s2#, MutableArray# s e
marr# #) -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
arr1# Int#
o1# MutableArray# s e
marr# Int#
0# Int#
n1# State# s
s2# of
State# s
s3# -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
arr2# Int#
o2# MutableArray# s e
marr# Int#
n1# Int#
n2# State# s
s3# of
State# s
s4# -> case MutableArray# s e -> State# s -> (# State# s, Array# e #)
forall d a.
MutableArray# d a -> State# d -> (# State# d, Array# a #)
unsafeFreezeArray# MutableArray# s e
marr# State# s
s4# of
(# State# s
s5#, Array# e
arr# #) -> (# State# s
s5#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int# -> Int
I# Int#
n#) Int
0 Array# e
arr# #)
where
n# :: Int#
n# = Int#
n1# Int# -> Int# -> Int#
+# Int#
n2#
force :: SArray# e -> SArray# e
force (SArray# n :: Int
n@(I# Int#
n#) (I# Int#
o#) Array# e
arr#) = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ STRep s (SArray# e) -> ST s (SArray# e)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# e) -> ST s (SArray# e))
-> STRep s (SArray# e) -> ST s (SArray# e)
forall a b. (a -> b) -> a -> b
$
\ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# (String -> e
forall a. String -> a
unreachEx String
"force") State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
arr# Int#
o# MutableArray# s e
marr# Int#
0# Int#
n# State# s
s2# of
State# s
s3# -> case MutableArray# s e -> State# s -> (# State# s, Array# e #)
forall d a.
MutableArray# d a -> State# d -> (# State# d, Array# a #)
unsafeFreezeArray# MutableArray# s e
marr# State# s
s3# of
(# State# s
s4#, Array# e
copy# #) -> (# State# s
s4#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
n Int
0 Array# e
copy# #)
listL :: SArray# e -> [e]
listL = SArray# e -> [e]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
listR :: SArray# e -> [e]
listR = (e -> [e] -> [e]) -> [e] -> e -> [e]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (:) ([e] -> e -> [e]) -> [e] -> SArray# e -> [e]
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
`foldl` []
!^ :: SArray# e -> Int -> e
(!^) (SArray# Int
_ (I# Int#
o#) Array# e
arr#) = \ (I# Int#
i#) ->
case Array# e -> Int# -> (# e #)
forall a. Array# a -> Int# -> (# a #)
indexArray# Array# e
arr# (Int#
i# Int# -> Int# -> Int#
+# Int#
o#) of (# e
e #) -> e
e
write :: SArray# e -> Int -> e -> SArray# e
write SArray# e
es Int
n e
e = Bool -> Bool
not (SArray# e -> Int -> Bool
forall b i. Bordered b i => b -> i -> Bool
indexIn SArray# e
es Int
n) Bool -> SArray# e -> SArray# e -> SArray# e
forall a. Bool -> a -> a -> a
? SArray# e
es (SArray# e -> SArray# e) -> SArray# e -> SArray# e
forall a b. (a -> b) -> a -> b
$ (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ do
STArray# s e
es' <- SArray# e -> ST s (STArray# s e)
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
thaw SArray# e
es
STArray# s e -> Int -> e -> ST s ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM STArray# s e
es' Int
n e
e
STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done STArray# s e
es'
reverse :: SArray# e -> SArray# e
reverse SArray# e
es = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ SArray# e -> ST s (STArray# s e)
forall (m :: * -> *) v i e v' j.
(IndexedM m v i e, Indexed v' j e) =>
v' -> m v
fromIndexed' SArray# e
es ST s (STArray# s e)
-> (STArray# s e -> ST s (STArray# s e)) -> ST s (STArray# s e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => l -> m l
reversed ST s (STArray# s e)
-> (STArray# s e -> ST s (SArray# e)) -> ST s (SArray# e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done
concat :: f (SArray# e) -> SArray# e
concat f (SArray# e)
ess = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ do
let n :: Int
n = (SArray# e -> Int -> Int) -> Int -> f (SArray# e) -> Int
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr' (Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) (Int -> Int -> Int)
-> (SArray# e -> Int) -> SArray# e -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf) Int
0 f (SArray# e)
ess
marr :: STArray# s e
marr@(STArray# Int
_ Int
_ MutableArray# s e
marr#) <- Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
n (String -> e
forall a. String -> a
unreachEx String
"concat")
let
write# :: SArray# e -> Int -> ST s Int
write# (SArray# c :: Int
c@(I# Int#
c#) (I# Int#
o#) Array# e
arr#) i :: Int
i@(I# Int#
i#) = STRep s Int -> ST s Int
forall s a. STRep s a -> ST s a
ST (STRep s Int -> ST s Int) -> STRep s Int -> ST s Int
forall a b. (a -> b) -> a -> b
$
\ State# s
s2# -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
arr# Int#
o# MutableArray# s e
marr# Int#
i# Int#
c# State# s
s2# of
State# s
s3# -> (# State# s
s3#, Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
c #)
ST s Int -> ST s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ST s Int -> ST s ()) -> ST s Int -> ST s ()
forall a b. (a -> b) -> a -> b
$ (ST s Int -> SArray# e -> ST s Int)
-> ST s Int -> f (SArray# e) -> ST s Int
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (\ ST s Int
b SArray# e
a -> SArray# e -> Int -> ST s Int
write# SArray# e
a (Int -> ST s Int) -> ST s Int -> ST s Int
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ST s Int
b) (Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
0) f (SArray# e)
ess
STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done STArray# s e
marr
select :: (e -> Maybe a) -> SArray# e -> [a]
select e -> Maybe a
f = (e -> [a] -> [a]) -> [a] -> SArray# e -> [a]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\ e
o [a]
es -> case e -> Maybe a
f e
o of {Just a
e -> a
e a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
es; Maybe a
_ -> [a]
es}) []
extract :: (e -> Maybe a) -> SArray# e -> ([a], SArray# e)
extract e -> Maybe a
f =
let g :: e -> ([a], [e]) -> ([a], [e])
g = \ e
o -> case e -> Maybe a
f e
o of {Just a
e -> ([a] -> [a]) -> ([a], [e]) -> ([a], [e])
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (a
e a -> [a] -> [a]
forall a. a -> [a] -> [a]
:); Maybe a
_ -> ([e] -> [e]) -> ([a], [e]) -> ([a], [e])
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (e
o e -> [e] -> [e]
forall a. a -> [a] -> [a]
:)}
in ([e] -> SArray# e) -> ([a], [e]) -> ([a], SArray# e)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second [e] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList (([a], [e]) -> ([a], SArray# e))
-> (SArray# e -> ([a], [e])) -> SArray# e -> ([a], SArray# e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> ([a], [e]) -> ([a], [e]))
-> ([a], [e]) -> SArray# e -> ([a], [e])
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr e -> ([a], [e]) -> ([a], [e])
g ([], [])
selects :: f (e -> Maybe a) -> SArray# e -> ([[a]], SArray# e)
selects f (e -> Maybe a)
fs = ([e] -> SArray# e) -> ([[a]], [e]) -> ([[a]], SArray# e)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second [e] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList (([[a]], [e]) -> ([[a]], SArray# e))
-> (SArray# e -> ([[a]], [e])) -> SArray# e -> ([[a]], SArray# e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (e -> Maybe a) -> [e] -> ([[a]], [e])
forall l e (f :: * -> *) a.
(Linear l e, Foldable f) =>
f (e -> Maybe a) -> l -> ([[a]], l)
selects f (e -> Maybe a)
fs ([e] -> ([[a]], [e]))
-> (SArray# e -> [e]) -> SArray# e -> ([[a]], [e])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> [e]
forall l e. Linear l e => l -> [e]
listL
ofoldr :: (Int -> e -> b -> b) -> b -> SArray# e -> b
ofoldr Int -> e -> b -> b
f b
base = \ arr :: SArray# e
arr@(SArray# Int
c Int
_ Array# e
_) ->
let go :: Int -> b
go Int
i = Int
c Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> b -> b -> b
forall a. Bool -> a -> a -> a
? b
base (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ Int -> e -> b -> b
f Int
i (SArray# e
arr SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i) (Int -> b
go (Int -> b) -> Int -> b
forall a b. (a -> b) -> a -> b
$ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
in Int -> b
go Int
0
ofoldl :: (Int -> b -> e -> b) -> b -> SArray# e -> b
ofoldl Int -> b -> e -> b
f b
base = \ arr :: SArray# e
arr@(SArray# Int
c Int
_ Array# e
_) ->
let go :: Int -> b
go Int
i = -Int
1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> b -> b -> b
forall a. Bool -> a -> a -> a
? b
base (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ Int -> b -> e -> b
f Int
i (Int -> b
go (Int -> b) -> Int -> b
forall a b. (a -> b) -> a -> b
$ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (SArray# e
arr SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
in Int -> b
go (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
o_foldr :: (e -> b -> b) -> b -> SArray# e -> b
o_foldr = (e -> b -> b) -> b -> SArray# e -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr
o_foldl :: (b -> e -> b) -> b -> SArray# e -> b
o_foldl = (b -> e -> b) -> b -> SArray# e -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl
instance Split (SArray# e) e
where
take :: Int -> SArray# e -> SArray# e
take Int
n es :: SArray# e
es@(SArray# Int
c Int
o Array# e
arr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = SArray# e
forall e. Nullable e => e
Z
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = SArray# e
es
| Bool
True = Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
n Int
o Array# e
arr#
drop :: Int -> SArray# e -> SArray# e
drop Int
n es :: SArray# e
es@(SArray# Int
c Int
o Array# e
arr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = SArray# e
es
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = SArray# e
forall e. Nullable e => e
Z
| Bool
True = Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) Array# e
arr#
split :: Int -> SArray# e -> (SArray# e, SArray# e)
split Int
n es :: SArray# e
es@(SArray# Int
c Int
o Array# e
arr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = (SArray# e
forall e. Nullable e => e
Z, SArray# e
es)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = (SArray# e
es, SArray# e
forall e. Nullable e => e
Z)
| Bool
True = (Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
n Int
o Array# e
arr#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) Array# e
arr#)
keep :: Int -> SArray# e -> SArray# e
keep Int
n es :: SArray# e
es@(SArray# Int
c Int
o Array# e
arr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = SArray# e
forall e. Nullable e => e
Z
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = SArray# e
es
| Bool
True = Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
n (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) Array# e
arr#
sans :: Int -> SArray# e -> SArray# e
sans Int
n es :: SArray# e
es@(SArray# Int
c Int
o Array# e
arr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = SArray# e
es
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = SArray# e
forall e. Nullable e => e
Z
| Bool
True = Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) Int
o Array# e
arr#
divide :: Int -> SArray# e -> (SArray# e, SArray# e)
divide Int
n es :: SArray# e
es@(SArray# Int
c Int
o Array# e
arr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = (SArray# e
forall e. Nullable e => e
Z, SArray# e
es)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = (SArray# e
es, SArray# e
forall e. Nullable e => e
Z)
| Bool
True = (Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
n (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) Array# e
arr#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) Int
o Array# e
arr#)
splitsBy :: (e -> Bool) -> SArray# e -> [SArray# e]
splitsBy e -> Bool
f SArray# e
es = (e -> Bool) -> SArray# e -> SArray# e
forall s e. Split s e => (e -> Bool) -> s -> s
dropWhile e -> Bool
f (SArray# e -> SArray# e) -> [SArray# e] -> [SArray# e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> Bool
f (e -> Bool) -> SArray# e -> [Int]
forall map key e. Map map key e => (e -> Bool) -> map -> [key]
*$ SArray# e
es [Int] -> SArray# e -> [SArray# e]
forall s e (f :: * -> *).
(Split s e, Foldable f) =>
f Int -> s -> [s]
`parts` SArray# e
es
justifyL :: Int -> e -> SArray# e -> SArray# e
justifyL n :: Int
n@(I# Int#
n#) e
e es :: SArray# e
es@(SArray# c :: Int
c@(I# Int#
c#) (I# Int#
o#) Array# e
src#) = case Int
c Compare Int
forall o. Ord o => Compare o
<=> Int
n of
Ordering
EQ -> SArray# e
es
Ordering
GT -> Int -> SArray# e -> SArray# e
forall s e. Split s e => Int -> s -> s
take Int
n SArray# e
es
Ordering
LT -> (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ STRep s (SArray# e) -> ST s (SArray# e)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# e) -> ST s (SArray# e))
-> STRep s (SArray# e) -> ST s (SArray# e)
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# e
e State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
src# Int#
o# MutableArray# s e
marr# Int#
0# Int#
c# State# s
s2# of
State# s
s3# -> case MutableArray# s e -> State# s -> (# State# s, Array# e #)
forall d a.
MutableArray# d a -> State# d -> (# State# d, Array# a #)
unsafeFreezeArray# MutableArray# s e
marr# State# s
s3# of
(# State# s
s4#, Array# e
arr# #) -> (# State# s
s4#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
n Int
0 Array# e
arr# #)
justifyR :: Int -> e -> SArray# e -> SArray# e
justifyR n :: Int
n@(I# Int#
n#) e
e es :: SArray# e
es@(SArray# c :: Int
c@(I# Int#
c#) (I# Int#
o#) Array# e
src#) = case Int
c Compare Int
forall o. Ord o => Compare o
<=> Int
n of
Ordering
EQ -> SArray# e
es
Ordering
GT -> Int -> SArray# e -> SArray# e
forall s e. Split s e => Int -> s -> s
take Int
n SArray# e
es
Ordering
LT -> (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ STRep s (SArray# e) -> ST s (SArray# e)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# e) -> ST s (SArray# e))
-> STRep s (SArray# e) -> ST s (SArray# e)
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# e
e State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
src# Int#
o# MutableArray# s e
marr# (Int#
n# Int# -> Int# -> Int#
-# Int#
c#) Int#
c# State# s
s2# of
State# s
s3# -> case MutableArray# s e -> State# s -> (# State# s, Array# e #)
forall d a.
MutableArray# d a -> State# d -> (# State# d, Array# a #)
unsafeFreezeArray# MutableArray# s e
marr# State# s
s3# of
(# State# s
s4#, Array# e
arr# #) -> (# State# s
s4#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
n Int
0 Array# e
arr# #)
combo :: Equal e -> SArray# e -> Int
combo Equal e
_ SArray# e
Z = Int
0
combo Equal e
f es :: SArray# e
es@(SArray# Int
n Int
_ Array# e
_) =
let go :: e -> Int -> Int
go e
e Int
i = let e' :: e
e' = SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i in Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n Bool -> Bool -> Bool
|| Bool -> Bool
not (Equal e
f e
e e
e') Bool -> Int -> Int -> Int
forall a. Bool -> a -> a -> a
? Int
i (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ e -> Int -> Int
go e
e' (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
in e -> Int -> Int
go (SArray# e -> e
forall l e. Linear l e => l -> e
head SArray# e
es) Int
1
each :: Int -> SArray# e -> SArray# e
each Int
n es :: SArray# e
es@(SArray# Int
c Int
_ Array# e
_) =
let go :: Int -> [e]
go Int
i = Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
c Bool -> [e] -> [e] -> [e]
forall a. Bool -> a -> a -> a
? SArray# e
esSArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^Int
i e -> [e] -> [e]
forall a. a -> [a] -> [a]
: Int -> [e]
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) ([e] -> [e]) -> [e] -> [e]
forall a b. (a -> b) -> a -> b
$ []
in case Int
n Compare Int
forall o. Ord o => Compare o
<=> Int
1 of {Ordering
LT -> SArray# e
forall e. Nullable e => e
Z; Ordering
EQ -> SArray# e
es; Ordering
GT -> [e] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList ([e] -> SArray# e) -> [e] -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> [e]
go (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)}
isPrefixOf :: SArray# e -> SArray# e -> Bool
isPrefixOf xs :: SArray# e
xs@(SArray# Int
c1 Int
_ Array# e
_) ys :: SArray# e
ys@(SArray# Int
c2 Int
_ Array# e
_) =
let eq :: Int -> Bool
eq Int
i = Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
c1 Bool -> Bool -> Bool
|| (SArray# e
xs SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i) Equal e
forall a. Eq a => a -> a -> Bool
== (SArray# e
ys SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i) Bool -> Bool -> Bool
&& Int -> Bool
eq (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
in Int
c1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
c2 Bool -> Bool -> Bool
&& Int -> Bool
eq Int
0
isSuffixOf :: SArray# e -> SArray# e -> Bool
isSuffixOf xs :: SArray# e
xs@(SArray# Int
c1 Int
_ Array# e
_) ys :: SArray# e
ys@(SArray# Int
c2 Int
_ Array# e
_) =
let eq :: Int -> Int -> Bool
eq Int
i Int
j = Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
c1 Bool -> Bool -> Bool
|| (SArray# e
xs SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i) Equal e
forall a. Eq a => a -> a -> Bool
== (SArray# e
ys SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
j) Bool -> Bool -> Bool
&& Int -> Int -> Bool
eq (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
in Int
c1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
c2 Bool -> Bool -> Bool
&& Int -> Int -> Bool
eq Int
0 (Int
c2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
c1)
selectWhile :: (e -> Maybe a) -> SArray# e -> [a]
selectWhile e -> Maybe a
f es :: SArray# e
es@(SArray# Int
c Int
_ Array# e
_) =
let go :: Int -> [a]
go Int
i = Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
c Bool -> [a] -> [a] -> [a]
forall a. Bool -> a -> a -> a
? [] ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ [a] -> (a -> [a]) -> Maybe a -> [a]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (a -> [a] -> [a]
forall a. a -> [a] -> [a]
: Int -> [a]
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)) (Maybe a -> [a]) -> Maybe a -> [a]
forall a b. (a -> b) -> a -> b
$ e -> Maybe a
f (SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
in Int -> [a]
go Int
0
selectEnd :: (e -> Maybe a) -> SArray# e -> [a]
selectEnd e -> Maybe a
g xs :: SArray# e
xs@(SArray# Int
c Int
_ Array# e
_) =
let go :: Int -> SArray# e -> [a]
go Int
i SArray# e
es = Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> [a] -> [a] -> [a]
forall a. Bool -> a -> a -> a
? [] ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ [a] -> (a -> [a]) -> Maybe a -> [a]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (a -> [a] -> [a]
forall a. a -> [a] -> [a]
: Int -> SArray# e -> [a]
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) SArray# e
es) (Maybe a -> [a]) -> Maybe a -> [a]
forall a b. (a -> b) -> a -> b
$ e -> Maybe a
g (SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
in [a] -> [a]
forall l e. Linear l e => l -> l
reverse ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ Int -> SArray# e -> [a]
go (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) SArray# e
xs
instance Bordered (SArray# e) Int
where
lower :: SArray# e -> Int
lower SArray# e
_ = Int
0
sizeOf :: SArray# e -> Int
sizeOf (SArray# Int
c Int
_ Array# e
_) = Int
c
upper :: SArray# e -> Int
upper (SArray# Int
c Int
_ Array# e
_) = Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
bounds :: SArray# e -> (Int, Int)
bounds (SArray# Int
c Int
_ Array# e
_) = (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
indices :: SArray# e -> [Int]
indices (SArray# Int
c Int
_ Array# e
_) = [Int
0 .. Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
indexOf :: SArray# e -> Int -> Int
indexOf (SArray# Int
c Int
_ Array# e
_) = (Int, Int) -> Int -> Int
forall i. Index i => (i, i) -> Int -> i
index (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
offsetOf :: SArray# e -> Int -> Int
offsetOf (SArray# Int
c Int
_ Array# e
_) = (Int, Int) -> Int -> Int
forall i. Index i => (i, i) -> i -> Int
offset (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
indexIn :: SArray# e -> Int -> Bool
indexIn (SArray# Int
c Int
_ Array# e
_) = \ Int
i -> Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
c
instance (Ord e) => Set (SArray# e) e
instance SetWith (SArray# e) e
where
setWith :: Compare e -> SArray# e -> SArray# e
setWith Compare e
f = Compare e -> SArray# e -> SArray# e
forall e. Compare e -> SArray# e -> SArray# e
nubSorted Compare e
f (SArray# e -> SArray# e)
-> (SArray# e -> SArray# e) -> SArray# e -> SArray# e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compare e -> SArray# e -> SArray# e
forall s e. Sort s e => Compare e -> s -> s
sortBy Compare e
f
insertWith :: Compare e -> e -> SArray# e -> SArray# e
insertWith Compare e
f e
e SArray# e
es = case (\ e
x -> e
x Compare e
`f` e
e Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
LT) (e -> Bool) -> SArray# e -> Maybe Int
forall map key e. Map map key e => (e -> Bool) -> map -> Maybe key
.$ SArray# e
es of
Just Int
i -> e
e Compare e
`f` (SArray# e
esSArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^Int
i) Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ Bool -> SArray# e -> SArray# e -> SArray# e
forall a. Bool -> a -> a -> a
? SArray# e
es (SArray# e -> SArray# e) -> SArray# e -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> e -> SArray# e -> SArray# e
forall e. Int -> e -> SArray# e -> SArray# e
before Int
i e
e SArray# e
es
Maybe Int
Nothing -> SArray# e
es SArray# e -> e -> SArray# e
forall l e. Linear l e => l -> e -> l
:< e
e
deleteWith :: Compare e -> e -> SArray# e -> SArray# e
deleteWith Compare e
f e
e SArray# e
es = Compare e -> e -> SArray# e -> Bool
forall s o. SetWith s o => Compare o -> o -> s -> Bool
memberWith Compare e
f e
e SArray# e
es Bool -> SArray# e -> SArray# e -> SArray# e
forall a. Bool -> a -> a -> a
? (e -> Bool) -> SArray# e -> SArray# e
forall l e. Linear l e => (e -> Bool) -> l -> l
except (\ e
x -> Compare e
f e
e e
x Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ) SArray# e
es (SArray# e -> SArray# e) -> SArray# e -> SArray# e
forall a b. (a -> b) -> a -> b
$ SArray# e
es
{-# INLINE intersectionWith #-}
intersectionWith :: Compare e -> SArray# e -> SArray# e -> SArray# e
intersectionWith Compare e
f xs :: SArray# e
xs@(SArray# Int
n1 Int
_ Array# e
_) ys :: SArray# e
ys@(SArray# Int
n2 Int
_ Array# e
_) = [e] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList ([e] -> SArray# e) -> [e] -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> Int -> [e]
go Int
0 Int
0
where
go :: Int -> Int -> [e]
go Int
i Int
j = Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n1 Bool -> Bool -> Bool
|| Int
j Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n2 Bool -> [e] -> [e] -> [e]
forall a. Bool -> a -> a -> a
? [] ([e] -> [e]) -> [e] -> [e]
forall a b. (a -> b) -> a -> b
$ case e
x Compare e
`f` e
y of
Ordering
EQ -> e
x e -> [e] -> [e]
forall a. a -> [a] -> [a]
: Int -> Int -> [e]
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Ordering
LT -> Int -> Int -> [e]
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
j
Ordering
GT -> Int -> Int -> [e]
go Int
i (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
where
x :: e
x = SArray# e
xs SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i
y :: e
y = SArray# e
ys SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
j
{-# INLINE unionWith #-}
unionWith :: Compare e -> SArray# e -> SArray# e -> SArray# e
unionWith Compare e
f xs :: SArray# e
xs@(SArray# Int
n1 Int
_ Array# e
_) ys :: SArray# e
ys@(SArray# Int
n2 Int
_ Array# e
_) = [e] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList ([e] -> SArray# e) -> [e] -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> Int -> [e]
go Int
0 Int
0
where
go :: Int -> Int -> [e]
go Int
i Int
j
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n1 = (SArray# e
ys SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^) (Int -> e) -> [Int] -> [e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int
j .. Int
n2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
| Int
j Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n2 = (SArray# e
xs SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^) (Int -> e) -> [Int] -> [e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int
i .. Int
n1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
| Bool
True = case e
x Compare e
`f` e
y of
Ordering
EQ -> e
x e -> [e] -> [e]
forall a. a -> [a] -> [a]
: Int -> Int -> [e]
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Ordering
LT -> e
x e -> [e] -> [e]
forall a. a -> [a] -> [a]
: Int -> Int -> [e]
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
j
Ordering
GT -> e
y e -> [e] -> [e]
forall a. a -> [a] -> [a]
: Int -> Int -> [e]
go Int
i (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
where
x :: e
x = SArray# e
xs SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i
y :: e
y = SArray# e
ys SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
j
{-# INLINE differenceWith #-}
differenceWith :: Compare e -> SArray# e -> SArray# e -> SArray# e
differenceWith Compare e
f xs :: SArray# e
xs@(SArray# Int
n1 Int
_ Array# e
_) ys :: SArray# e
ys@(SArray# Int
n2 Int
_ Array# e
_) = [e] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList ([e] -> SArray# e) -> [e] -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> Int -> [e]
go Int
0 Int
0
where
go :: Int -> Int -> [e]
go Int
i Int
j
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n1 = []
| Int
j Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n2 = (SArray# e
xs SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^) (Int -> e) -> [Int] -> [e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int
i .. Int
n1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
| Bool
True = case e
x Compare e
`f` e
y of
Ordering
EQ -> Int -> Int -> [e]
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Ordering
LT -> e
x e -> [e] -> [e]
forall a. a -> [a] -> [a]
: Int -> Int -> [e]
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
j
Ordering
GT -> Int -> Int -> [e]
go Int
i (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
where
x :: e
x = SArray# e
xs SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i
y :: e
y = SArray# e
ys SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
j
{-# INLINE symdiffWith #-}
symdiffWith :: Compare e -> SArray# e -> SArray# e -> SArray# e
symdiffWith Compare e
f xs :: SArray# e
xs@(SArray# Int
n1 Int
_ Array# e
_) ys :: SArray# e
ys@(SArray# Int
n2 Int
_ Array# e
_) = [e] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList ([e] -> SArray# e) -> [e] -> SArray# e
forall a b. (a -> b) -> a -> b
$ Int -> Int -> [e]
symdiff' Int
0 Int
0
where
symdiff' :: Int -> Int -> [e]
symdiff' Int
i Int
j
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n1 = (SArray# e
ys SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^) (Int -> e) -> [Int] -> [e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int
j .. Int
n2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
| Int
j Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n2 = (SArray# e
xs SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^) (Int -> e) -> [Int] -> [e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int
i .. Int
n1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
| Bool
True = case e
x Compare e
`f` e
y of
Ordering
EQ -> Int -> Int -> [e]
symdiff' (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Ordering
LT -> e
x e -> [e] -> [e]
forall a. a -> [a] -> [a]
: Int -> Int -> [e]
symdiff' (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
j
Ordering
GT -> e
y e -> [e] -> [e]
forall a. a -> [a] -> [a]
: Int -> Int -> [e]
symdiff' Int
i (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
where
x :: e
x = SArray# e
xs SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i
y :: e
y = SArray# e
ys SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
j
memberWith :: Compare e -> e -> SArray# e -> Bool
memberWith = Compare e -> e -> SArray# e -> Bool
forall v e i.
(Linear v e, Bordered v i) =>
Compare e -> e -> v -> Bool
binaryContain
lookupLTWith :: Compare e -> e -> SArray# e -> Maybe e
lookupLTWith Compare e
_ e
_ SArray# e
Z = Maybe e
forall a. Maybe a
Nothing
lookupLTWith Compare e
f e
o SArray# e
es
| Ordering
GT <- e
o Compare e
`f` e
last' = e -> Maybe e
forall a. a -> Maybe a
Just e
last'
| Ordering
GT <- e
o Compare e
`f` e
head' = e -> Int -> Int -> Maybe e
look' e
head' Int
0 Int
u'
| Bool
True = Maybe e
forall a. Maybe a
Nothing
where
head' :: e
head' = SArray# e
es SArray# e -> Int -> e
forall map key e. Map map key e => map -> key -> e
.! Int
0
last' :: e
last' = SArray# e
es SArray# e -> Int -> e
forall map key e. Map map key e => map -> key -> e
.! Int
u'
u' :: Int
u' = SArray# e -> Int
forall b i. Bordered b i => b -> i
upper SArray# e
es
look' :: e -> Int -> Int -> Maybe e
look' e
r Int
l Int
u = Int
l Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
u Bool -> Maybe e -> Maybe e -> Maybe e
forall a. Bool -> a -> a -> a
? e -> Maybe e
forall a. a -> Maybe a
Just e
r (Maybe e -> Maybe e) -> Maybe e -> Maybe e
forall a b. (a -> b) -> a -> b
$ case e
o Compare e
`f` e
e of
Ordering
EQ -> e -> Maybe e
forall a. a -> Maybe a
Just (e -> Maybe e) -> e -> Maybe e
forall a b. (a -> b) -> a -> b
$ Int
j Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
1 Bool -> e -> e -> e
forall a. Bool -> a -> a -> a
? e
r (e -> e) -> e -> e
forall a b. (a -> b) -> a -> b
$ SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
Ordering
LT -> e -> Int -> Int -> Maybe e
look' e
r Int
l (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
Ordering
GT -> e -> Int -> Int -> Maybe e
look' e
e (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
u
where
j :: Int
j = Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
u Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
l) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
e :: e
e = SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
j
lookupLEWith :: Compare e -> e -> SArray# e -> Maybe e
lookupLEWith Compare e
_ e
_ SArray# e
Z = Maybe e
forall a. Maybe a
Nothing
lookupLEWith Compare e
f e
o SArray# e
es
| Ordering
GT <- e
o Compare e
`f` e
last' = e -> Maybe e
forall a. a -> Maybe a
Just e
last'
| Ordering
LT <- e
o Compare e
`f` e
head' = Maybe e
forall a. Maybe a
Nothing
| Bool
True = e -> Int -> Int -> Maybe e
look' e
head' Int
0 Int
u'
where
head' :: e
head' = SArray# e
es SArray# e -> Int -> e
forall map key e. Map map key e => map -> key -> e
.! Int
0
last' :: e
last' = SArray# e
es SArray# e -> Int -> e
forall map key e. Map map key e => map -> key -> e
.! Int
u'
u' :: Int
u' = SArray# e -> Int
forall b i. Bordered b i => b -> i
upper SArray# e
es
look' :: e -> Int -> Int -> Maybe e
look' e
r Int
l Int
u = Int
l Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
u Bool -> Maybe e -> Maybe e -> Maybe e
forall a. Bool -> a -> a -> a
? e -> Maybe e
forall a. a -> Maybe a
Just e
r (Maybe e -> Maybe e) -> Maybe e -> Maybe e
forall a b. (a -> b) -> a -> b
$ case e
o Compare e
`f` e
e of
Ordering
LT -> e -> Int -> Int -> Maybe e
look' e
r Int
l (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
Ordering
_ -> e -> Int -> Int -> Maybe e
look' e
e (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
u
where
j :: Int
j = Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
u Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
l) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
e :: e
e = SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
j
lookupGTWith :: Compare e -> e -> SArray# e -> Maybe e
lookupGTWith Compare e
_ e
_ SArray# e
Z = Maybe e
forall a. Maybe a
Nothing
lookupGTWith Compare e
f e
o SArray# e
es
| Ordering
LT <- e
o Compare e
`f` e
head' = e -> Maybe e
forall a. a -> Maybe a
Just e
head'
| Ordering
LT <- e
o Compare e
`f` e
last' = e -> Int -> Int -> Maybe e
look' e
last' Int
0 Int
u'
| Bool
True = Maybe e
forall a. Maybe a
Nothing
where
head' :: e
head' = SArray# e
es SArray# e -> Int -> e
forall map key e. Map map key e => map -> key -> e
.! Int
0
last' :: e
last' = SArray# e
es SArray# e -> Int -> e
forall map key e. Map map key e => map -> key -> e
.! Int
u'
u' :: Int
u' = SArray# e -> Int
forall b i. Bordered b i => b -> i
upper SArray# e
es
look' :: e -> Int -> Int -> Maybe e
look' e
r Int
l Int
u = Int
l Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
u Bool -> Maybe e -> Maybe e -> Maybe e
forall a. Bool -> a -> a -> a
? e -> Maybe e
forall a. a -> Maybe a
Just e
r (Maybe e -> Maybe e) -> Maybe e -> Maybe e
forall a b. (a -> b) -> a -> b
$ case e
o Compare e
`f` e
e of
Ordering
LT -> e -> Int -> Int -> Maybe e
look' e
e Int
l (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
Ordering
EQ -> Int
j Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
u' Bool -> Maybe e -> Maybe e -> Maybe e
forall a. Bool -> a -> a -> a
? Maybe e
forall a. Maybe a
Nothing (Maybe e -> Maybe e) -> Maybe e -> Maybe e
forall a b. (a -> b) -> a -> b
$ e -> Maybe e
forall a. a -> Maybe a
Just (SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1))
Ordering
GT -> e -> Int -> Int -> Maybe e
look' e
r (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
u
where
j :: Int
j = Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
u Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
l) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
e :: e
e = SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
j
lookupGEWith :: Compare e -> e -> SArray# e -> Maybe e
lookupGEWith Compare e
_ e
_ SArray# e
Z = Maybe e
forall a. Maybe a
Nothing
lookupGEWith Compare e
f e
o SArray# e
es
| Ordering
GT <- e
o Compare e
`f` e
last' = Maybe e
forall a. Maybe a
Nothing
| Ordering
GT <- e
o Compare e
`f` e
head' = e -> Int -> Int -> Maybe e
look' e
last' Int
0 Int
u'
| Bool
True = e -> Maybe e
forall a. a -> Maybe a
Just e
head'
where
head' :: e
head' = SArray# e
es SArray# e -> Int -> e
forall map key e. Map map key e => map -> key -> e
.! Int
0
last' :: e
last' = SArray# e
es SArray# e -> Int -> e
forall map key e. Map map key e => map -> key -> e
.! Int
u'
u' :: Int
u' = SArray# e -> Int
forall b i. Bordered b i => b -> i
upper SArray# e
es
look' :: e -> Int -> Int -> Maybe e
look' e
r Int
l Int
u = Int
l Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
u Bool -> Maybe e -> Maybe e -> Maybe e
forall a. Bool -> a -> a -> a
? e -> Maybe e
forall a. a -> Maybe a
Just e
r (Maybe e -> Maybe e) -> Maybe e -> Maybe e
forall a b. (a -> b) -> a -> b
$ case e
o Compare e
`f` e
e of
Ordering
LT -> e -> Int -> Int -> Maybe e
look' e
e Int
l (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
Ordering
EQ -> e -> Maybe e
forall a. a -> Maybe a
Just e
e
Ordering
GT -> e -> Int -> Int -> Maybe e
look' e
r (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
u
where
j :: Int
j = Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
u Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
l) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
e :: e
e = SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
j
instance Scan (SArray# e) e
instance Sort (SArray# e) e
where
sortBy :: Compare e -> SArray# e -> SArray# e
sortBy Compare e
cmp SArray# e
es = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ do STArray# s e
es' <- SArray# e -> ST s (STArray# s e)
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
thaw SArray# e
es; Compare e -> STArray# s e -> ST s ()
forall (m :: * -> *) v e i.
(LinearM m v e, BorderedM m v i) =>
Compare e -> v -> m ()
timSortBy Compare e
cmp STArray# s e
es'; STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done STArray# s e
es'
sortedBy :: (e -> e -> Bool) -> SArray# e -> Bool
sortedBy e -> e -> Bool
f SArray# e
es = (e -> e -> Bool) -> SArray# e -> SArray# e -> Bool
forall (z :: * -> *) a b.
Zip z =>
(a -> b -> Bool) -> z a -> z b -> Bool
all2 e -> e -> Bool
f SArray# e
es (SArray# e -> SArray# e
forall l e. Linear l e => l -> l
tail SArray# e
es)
instance Map (SArray# e) Int e
where
toMap' :: e -> [(Int, e)] -> SArray# e
toMap' e
e [(Int, e)]
ascs = [(Int, e)] -> Bool
forall e. Nullable e => e -> Bool
isNull [(Int, e)]
ascs Bool -> SArray# e -> SArray# e -> SArray# e
forall a. Bool -> a -> a -> a
? SArray# e
forall e. Nullable e => e
Z (SArray# e -> SArray# e) -> SArray# e -> SArray# e
forall a b. (a -> b) -> a -> b
$ (Int, Int) -> e -> [(Int, e)] -> SArray# e
forall v i e. Indexed v i e => (i, i) -> e -> [(i, e)] -> v
assoc' ([(Int, e)] -> (Int, Int)
forall a b. Ord a => [(a, b)] -> (a, a)
ascsBounds [(Int, e)]
ascs) e
e [(Int, e)]
ascs
SArray# e
Z // :: SArray# e -> [(Int, e)] -> SArray# e
// [(Int, e)]
ascs = [(Int, e)] -> SArray# e
forall map key e. Map map key e => [(key, e)] -> map
toMap [(Int, e)]
ascs
SArray# e
es // [(Int, e)]
ascs = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ SArray# e -> ST s (STArray# s e)
forall (m :: * -> *) l e (f :: * -> *).
(LinearM m l e, Foldable f) =>
f e -> m l
fromFoldableM SArray# e
es ST s (STArray# s e)
-> (STArray# s e -> ST s (STArray# s e)) -> ST s (STArray# s e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (STArray# s e -> [(Int, e)] -> ST s (STArray# s e)
forall (m :: * -> *) map key e.
MapM m map key e =>
map -> [(key, e)] -> m map
`overwrite` [(Int, e)]
ascs) ST s (STArray# s e)
-> (STArray# s e -> ST s (SArray# e)) -> ST s (SArray# e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done
*$ :: (e -> Bool) -> SArray# e -> [Int]
(*$) e -> Bool
p = (Int -> e -> [Int] -> [Int]) -> [Int] -> SArray# e -> [Int]
forall l e b. Linear l e => (Int -> e -> b -> b) -> b -> l -> b
ofoldr (\ Int
i e
e [Int]
is -> e -> Bool
p e
e Bool -> [Int] -> [Int] -> [Int]
forall a. Bool -> a -> a -> a
? (Int
i Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
: [Int]
is) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ [Int]
is) []
.! :: SArray# e -> Int -> e
(.!) = SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
(!^)
kfoldr :: (Int -> e -> b -> b) -> b -> SArray# e -> b
kfoldr = (Int -> e -> b -> b) -> b -> SArray# e -> b
forall l e b. Linear l e => (Int -> e -> b -> b) -> b -> l -> b
ofoldr
kfoldl :: (Int -> b -> e -> b) -> b -> SArray# e -> b
kfoldl = (Int -> b -> e -> b) -> b -> SArray# e -> b
forall l e b. Linear l e => (Int -> b -> e -> b) -> b -> l -> b
ofoldl
instance Indexed (SArray# e) Int e
where
assoc' :: (Int, Int) -> e -> [(Int, e)] -> SArray# e
assoc' (Int, Int)
bnds e
defvalue [(Int, e)]
ascs = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ (Int, Int) -> e -> [(Int, e)] -> ST s (STArray# s e)
forall (m :: * -> *) v i e.
IndexedM m v i e =>
(i, i) -> e -> [(i, e)] -> m v
fromAssocs' (Int, Int)
bnds e
defvalue [(Int, e)]
ascs ST s (STArray# s e)
-> (STArray# s e -> ST s (SArray# e)) -> ST s (SArray# e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done
fromIndexed :: m -> SArray# e
fromIndexed m
es = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ do
let n :: Int
n = m -> Int
forall b i. Bordered b i => b -> Int
sizeOf m
es
STArray# s e
copy <- Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
n (String -> e
forall a. String -> a
unreachEx String
"fromIndexed")
[Int] -> (Int -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \ Int
i -> STArray# s e -> Int -> e -> ST s ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM STArray# s e
copy Int
i (m
es m -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done STArray# s e
copy
instance Thaw (ST s) (SArray# e) (STArray# s e)
where
thaw :: SArray# e -> ST s (STArray# s e)
thaw (SArray# c :: Int
c@(I# Int#
c#) (I# Int#
o#) Array# e
arr#) = STRep s (STArray# s e) -> ST s (STArray# s e)
forall s a. STRep s a -> ST s a
ST (STRep s (STArray# s e) -> ST s (STArray# s e))
-> STRep s (STArray# s e) -> ST s (STArray# s e)
forall a b. (a -> b) -> a -> b
$
\ State# s
s1# -> case Array# e
-> Int# -> Int# -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Array# a
-> Int# -> Int# -> State# d -> (# State# d, MutableArray# d a #)
thawArray# Array# e
arr# Int#
o# Int#
c# State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> (# State# s
s2#, Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
c Int
0 MutableArray# s e
marr# #)
unsafeThaw :: SArray# e -> ST s (STArray# s e)
unsafeThaw (SArray# Int
c Int
o Array# e
arr#) = STRep s (STArray# s e) -> ST s (STArray# s e)
forall s a. STRep s a -> ST s a
ST (STRep s (STArray# s e) -> ST s (STArray# s e))
-> STRep s (STArray# s e) -> ST s (STArray# s e)
forall a b. (a -> b) -> a -> b
$
\ State# s
s1# -> case Array# e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Array# a -> State# d -> (# State# d, MutableArray# d a #)
unsafeThawArray# Array# e
arr# State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> (# State# s
s2#, Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
c Int
o MutableArray# s e
marr# #)
instance Freeze (ST s) (STArray# s e) (SArray# e)
where
freeze :: STArray# s e -> ST s (SArray# e)
freeze (STArray# c :: Int
c@(I# Int#
c#) (I# Int#
o#) MutableArray# s e
marr#) = STRep s (SArray# e) -> ST s (SArray# e)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# e) -> ST s (SArray# e))
-> STRep s (SArray# e) -> ST s (SArray# e)
forall a b. (a -> b) -> a -> b
$
\ State# s
s1# -> case MutableArray# s e
-> Int# -> Int# -> State# s -> (# State# s, Array# e #)
forall d a.
MutableArray# d a
-> Int# -> Int# -> State# d -> (# State# d, Array# a #)
freezeArray# MutableArray# s e
marr# Int#
o# Int#
c# State# s
s1# of
(# State# s
s2#, Array# e
arr# #) -> (# State# s
s2#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
c Int
0 Array# e
arr# #)
unsafeFreeze :: STArray# s e -> ST s (SArray# e)
unsafeFreeze = STArray# s e -> ST s (SArray# e)
forall s e. STArray# s e -> ST s (SArray# e)
done
data STArray# s e = STArray#
{-# UNPACK #-} !Int
{-# UNPACK #-} !Int
!(MutableArray# s e)
deriving ( Typeable )
type role STArray# nominal representational
instance Eq (STArray# s e)
where
(STArray# Int
c1 Int
o1 MutableArray# s e
marr1#) == :: STArray# s e -> STArray# s e -> Bool
== (STArray# Int
c2 Int
o2 MutableArray# s e
marr2#) =
let same :: Bool
same = Int# -> Bool
isTrue# (MutableArray# s e -> MutableArray# s e -> Int#
forall d a. MutableArray# d a -> MutableArray# d a -> Int#
sameMutableArray# MutableArray# s e
marr1# MutableArray# s e
marr2#)
in Int
c1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
c2 Bool -> Bool -> Bool
&& (Int
c1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
|| Int
o1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
o2 Bool -> Bool -> Bool
&& Bool
same)
instance Estimate (STArray# s e)
where
<==> :: Compare (STArray# s e)
(<==>) = Compare Int -> (STArray# s e -> Int) -> Compare (STArray# s e)
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Compare Int
forall o. Ord o => Compare o
(<=>) STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.<=. :: STArray# s e -> STArray# s e -> Bool
(.<=.) = (Int -> Int -> Bool)
-> (STArray# s e -> Int) -> STArray# s e -> STArray# s e -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<=) STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.>=. :: STArray# s e -> STArray# s e -> Bool
(.>=.) = (Int -> Int -> Bool)
-> (STArray# s e -> Int) -> STArray# s e -> STArray# s e -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=) STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.>. :: STArray# s e -> STArray# s e -> Bool
(.>.) = (Int -> Int -> Bool)
-> (STArray# s e -> Int) -> STArray# s e -> STArray# s e -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>) STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.<. :: STArray# s e -> STArray# s e -> Bool
(.<.) = (Int -> Int -> Bool)
-> (STArray# s e -> Int) -> STArray# s e -> STArray# s e -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
<.=> :: STArray# s e -> Int -> Ordering
(<.=>) = Compare Int
forall o. Ord o => Compare o
(<=>) Compare Int
-> (STArray# s e -> Int) -> STArray# s e -> Int -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.>= :: STArray# s e -> Int -> Bool
(.>=) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=) (Int -> Int -> Bool)
-> (STArray# s e -> Int) -> STArray# s e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.<= :: STArray# s e -> Int -> Bool
(.<=) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<=) (Int -> Int -> Bool)
-> (STArray# s e -> Int) -> STArray# s e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.> :: STArray# s e -> Int -> Bool
(.>) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>) (Int -> Int -> Bool)
-> (STArray# s e -> Int) -> STArray# s e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.< :: STArray# s e -> Int -> Bool
(.<) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) (Int -> Int -> Bool)
-> (STArray# s e -> Int) -> STArray# s e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
instance Bordered (STArray# s e) Int
where
lower :: STArray# s e -> Int
lower STArray# s e
_ = Int
0
sizeOf :: STArray# s e -> Int
sizeOf (STArray# Int
c Int
_ MutableArray# s e
_) = Int
c
upper :: STArray# s e -> Int
upper (STArray# Int
c Int
_ MutableArray# s e
_) = Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
bounds :: STArray# s e -> (Int, Int)
bounds (STArray# Int
c Int
_ MutableArray# s e
_) = (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
indices :: STArray# s e -> [Int]
indices (STArray# Int
c Int
_ MutableArray# s e
_) = [Int
0 .. Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
indexOf :: STArray# s e -> Int -> Int
indexOf (STArray# Int
c Int
_ MutableArray# s e
_) = (Int, Int) -> Int -> Int
forall i. Index i => (i, i) -> Int -> i
index (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
offsetOf :: STArray# s e -> Int -> Int
offsetOf (STArray# Int
c Int
_ MutableArray# s e
_) = (Int, Int) -> Int -> Int
forall i. Index i => (i, i) -> i -> Int
offset (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
indexIn :: STArray# s e -> Int -> Bool
indexIn (STArray# Int
c Int
_ MutableArray# s e
_) = \ Int
i -> Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
c
instance BorderedM (ST s) (STArray# s e) Int
where
nowIndexIn :: STArray# s e -> Int -> ST s Bool
nowIndexIn (STArray# Int
c Int
_ MutableArray# s e
_) = Bool -> ST s Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> ST s Bool) -> (Int -> Bool) -> Int -> ST s Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, Int) -> Int -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
getIndices :: STArray# s e -> ST s [Int]
getIndices (STArray# Int
c Int
_ MutableArray# s e
_) = [Int] -> ST s [Int]
forall (m :: * -> *) a. Monad m => a -> m a
return [Int
0 .. Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
getBounds :: STArray# s e -> ST s (Int, Int)
getBounds (STArray# Int
c Int
_ MutableArray# s e
_) = (Int, Int) -> ST s (Int, Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
getUpper :: STArray# s e -> ST s Int
getUpper (STArray# Int
c Int
_ MutableArray# s e
_) = Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
getSizeOf :: STArray# s e -> ST s Int
getSizeOf (STArray# Int
c Int
_ MutableArray# s e
_) = Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
c
getLower :: STArray# s e -> ST s Int
getLower STArray# s e
_ = Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
0
instance LinearM (ST s) (STArray# s e) e
where
newNull :: ST s (STArray# s e)
newNull = STRep s (STArray# s e) -> ST s (STArray# s e)
forall s a. STRep s a -> ST s a
ST (STRep s (STArray# s e) -> ST s (STArray# s e))
-> STRep s (STArray# s e) -> ST s (STArray# s e)
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
0# (String -> e
forall a. String -> a
unreachEx String
"newNull") State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> (# State# s
s2#, Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
0 Int
0 MutableArray# s e
marr# #)
nowNull :: STArray# s e -> ST s Bool
nowNull STArray# s e
es = Bool -> ST s Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf STArray# s e
es Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
1)
getHead :: STArray# s e -> ST s e
getHead STArray# s e
es = STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) map key e.
MapM m map key e =>
map -> key -> m e
>! Int
0
getLast :: STArray# s e -> ST s e
getLast STArray# s e
es = STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) map key e.
MapM m map key e =>
map -> key -> m e
>! STArray# s e -> Int
forall b i. Bordered b i => b -> i
upper STArray# s e
es
newLinear :: [e] -> ST s (STArray# s e)
newLinear = [e] -> ST s (STArray# s e)
forall (m :: * -> *) l e (f :: * -> *).
(LinearM m l e, Foldable f) =>
f e -> m l
fromFoldableM
newLinearN :: Int -> [e] -> ST s (STArray# s e)
newLinearN Int
c [e]
es = STRep s (STArray# s e) -> ST s (STArray# s e)
forall s a. STRep s a -> ST s a
ST (STRep s (STArray# s e) -> ST s (STArray# s e))
-> STRep s (STArray# s e) -> ST s (STArray# s e)
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# e
forall a. a
err State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) ->
let go :: e -> (Int# -> State# s -> State# s) -> Int# -> State# s -> State# s
go e
y Int# -> State# s -> State# s
r = \ Int#
i# State# s
s3# -> case MutableArray# s e -> Int# -> e -> State# s -> State# s
forall d a. MutableArray# d a -> Int# -> a -> State# d -> State# d
writeArray# MutableArray# s e
marr# Int#
i# e
y State# s
s3# of
State# s
s4# -> if Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
==# Int#
n# Int# -> Int# -> Int#
-# Int#
1#) then State# s
s4# else Int# -> State# s -> State# s
r (Int#
i# Int# -> Int# -> Int#
+# Int#
1#) State# s
s4#
in Int -> MutableArray# s e -> STRep s (STArray# s e)
forall s e. Int -> MutableArray# s e -> STRep s (STArray# s e)
done' Int
n MutableArray# s e
marr# ( if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then State# s
s2# else (e
-> (Int# -> State# s -> State# s) -> Int# -> State# s -> State# s)
-> (Int# -> State# s -> State# s)
-> [e]
-> Int#
-> State# s
-> State# s
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr e -> (Int# -> State# s -> State# s) -> Int# -> State# s -> State# s
go (\ Int#
_ State# s
s# -> State# s
s#) [e]
es Int#
0# State# s
s2# )
where
err :: a
err = String -> a
forall a. String -> a
undEx String
"newLinearN"
!n :: Int
n@(I# Int#
n#) = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 Int
c
fromFoldableM :: f e -> ST s (STArray# s e)
fromFoldableM f e
es = STRep s (STArray# s e) -> ST s (STArray# s e)
forall s a. STRep s a -> ST s a
ST (STRep s (STArray# s e) -> ST s (STArray# s e))
-> STRep s (STArray# s e) -> ST s (STArray# s e)
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# e
forall a. a
err State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) ->
let go :: e -> (Int# -> State# s -> State# s) -> Int# -> State# s -> State# s
go e
y Int# -> State# s -> State# s
r = \ Int#
i# State# s
s3# -> case MutableArray# s e -> Int# -> e -> State# s -> State# s
forall d a. MutableArray# d a -> Int# -> a -> State# d -> State# d
writeArray# MutableArray# s e
marr# Int#
i# e
y State# s
s3# of
State# s
s4# -> if Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
==# Int#
n# Int# -> Int# -> Int#
-# Int#
1#) then State# s
s4# else Int# -> State# s -> State# s
r (Int#
i# Int# -> Int# -> Int#
+# Int#
1#) State# s
s4#
in Int -> MutableArray# s e -> STRep s (STArray# s e)
forall s e. Int -> MutableArray# s e -> STRep s (STArray# s e)
done' Int
n MutableArray# s e
marr# ( if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then State# s
s2# else (e
-> (Int# -> State# s -> State# s) -> Int# -> State# s -> State# s)
-> (Int# -> State# s -> State# s)
-> f e
-> Int#
-> State# s
-> State# s
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr e -> (Int# -> State# s -> State# s) -> Int# -> State# s -> State# s
go (\ Int#
_ State# s
s# -> State# s
s#) f e
es Int#
0# State# s
s2# )
where
err :: a
err = String -> a
forall a. String -> a
unreachEx String
"fromFoldableM"
!n :: Int
n@(I# Int#
n#) = f e -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length f e
es
getLeft :: STArray# s e -> ST s [e]
getLeft es :: STArray# s e
es@(STArray# Int
n Int
_ MutableArray# s e
_) = (STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#>) (Int -> ST s e) -> [Int] -> ST s [e]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
`mapM` [Int
0 .. Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
getRight :: STArray# s e -> ST s [e]
getRight es :: STArray# s e
es@(STArray# Int
n Int
_ MutableArray# s e
_) = (STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#>) (Int -> ST s e) -> [Int] -> ST s [e]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
`mapM` [Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1, Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2 .. Int
0]
{-# INLINE (!#>) #-}
!#> :: STArray# s e -> Int -> ST s e
(!#>) (STArray# Int
_ (I# Int#
o#) MutableArray# s e
marr#) = \ (I# Int#
i#) -> STRep s e -> ST s e
forall s a. STRep s a -> ST s a
ST (STRep s e -> ST s e) -> STRep s e -> ST s e
forall a b. (a -> b) -> a -> b
$ MutableArray# s e -> Int# -> STRep s e
forall d a.
MutableArray# d a -> Int# -> State# d -> (# State# d, a #)
readArray# MutableArray# s e
marr# (Int#
o# Int# -> Int# -> Int#
+# Int#
i#)
writeM :: STArray# s e -> Int -> e -> ST s ()
writeM = STArray# s e -> Int -> e -> ST s ()
forall (m :: * -> *) v i e. IndexedM m v i e => v -> i -> e -> m ()
writeM'
copied :: STArray# s e -> ST s (STArray# s e)
copied es :: STArray# s e
es@(STArray# Int
n Int
_ MutableArray# s e
_) = do
STArray# s e
copy <- Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
n (e -> ST s (STArray# s e)) -> e -> ST s (STArray# s e)
forall a b. (a -> b) -> a -> b
$ String -> e
forall a. String -> a
unreachEx String
"copied"
[Int] -> (Int -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \ Int
i -> STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i ST s e -> (e -> ST s ()) -> ST s ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> Int -> e -> ST s ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM STArray# s e
copy Int
i
STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
copy
copied' :: STArray# s e -> Int -> Int -> ST s (STArray# s e)
copied' STArray# s e
es Int
l Int
n = do
STArray# s e
copy <- Int
n Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
`filled` String -> e
forall a. String -> a
unreachEx String
"copied'"
[Int] -> (Int -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \ Int
i -> STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> (Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i) ST s e -> (e -> ST s ()) -> ST s ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> Int -> e -> ST s ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM STArray# s e
copy Int
i
STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
copy
reversed :: STArray# s e -> ST s (STArray# s e)
reversed STArray# s e
es =
let go :: Int -> Int -> ST s ()
go Int
i Int
j = Bool -> ST s () -> ST s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
j) (ST s () -> ST s ()) -> ST s () -> ST s ()
forall a b. (a -> b) -> a -> b
$ Int -> Int -> ST s ()
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ST s () -> ST s () -> ST s ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> STArray# s e -> Int -> Int -> ST s ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> Int -> m ()
swapM STArray# s e
es Int
i Int
j
in Int -> Int -> ST s ()
go Int
0 (STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf STArray# s e
es Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ST s () -> ST s (STArray# s e) -> ST s (STArray# s e)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
es
filled :: Int -> e -> ST s (STArray# s e)
filled Int
n e
e = let !n' :: Int
n'@(I# Int#
n#) = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 Int
n in STRep s (STArray# s e) -> ST s (STArray# s e)
forall s a. STRep s a -> ST s a
ST (STRep s (STArray# s e) -> ST s (STArray# s e))
-> STRep s (STArray# s e) -> ST s (STArray# s e)
forall a b. (a -> b) -> a -> b
$
\ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# e
e State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> (# State# s
s2#, Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
n' Int
0 MutableArray# s e
marr# #)
copyTo :: STArray# s e -> Int -> STArray# s e -> Int -> Int -> ST s ()
copyTo STArray# s e
src Int
sc STArray# s e
trg Int
tc n :: Int
n@(I# Int#
n#) = Bool -> ST s () -> ST s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0) (ST s () -> ST s ()) -> ST s () -> ST s ()
forall a b. (a -> b) -> a -> b
$ do
Bool -> ST s () -> ST s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
sc Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 Bool -> Bool -> Bool
|| Int
tc Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0) (ST s () -> ST s ()) -> ST s () -> ST s ()
forall a b. (a -> b) -> a -> b
$ String -> ST s ()
forall a. String -> a
underEx String
"copyTo"
Bool -> ST s () -> ST s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
sc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
n1 Bool -> Bool -> Bool
|| Int
tc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
n2) (ST s () -> ST s ()) -> ST s () -> ST s ()
forall a b. (a -> b) -> a -> b
$ String -> ST s ()
forall a. String -> a
overEx String
"copyTo"
STRep s () -> ST s ()
forall s a. STRep s a -> ST s a
ST (STRep s () -> ST s ()) -> STRep s () -> ST s ()
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# -> case MutableArray# s e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall d a.
MutableArray# d a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyMutableArray# MutableArray# s e
src# Int#
so# MutableArray# s e
trg# Int#
to# Int#
n# State# s
s1# of
State# s
s2# -> (# State# s
s2#, () #)
where
!(STArray# Int
n1 Int
o1 MutableArray# s e
src#) = STArray# s e
src; !(I# Int#
so#) = Int
o1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
sc
!(STArray# Int
n2 Int
o2 MutableArray# s e
trg#) = STArray# s e
trg; !(I# Int#
to#) = Int
o2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
tc
merged :: f (STArray# s e) -> ST s (STArray# s e)
merged f (STArray# s e)
ess = do
STArray# s e
marr <- Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
n (String -> e
forall a. String -> a
unreachEx String
"merged")
let writer :: STArray# s e -> Int -> ST s Int
writer arr :: STArray# s e
arr@(STArray# Int
c Int
_ MutableArray# s e
_) Int
i = (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
c) Int -> ST s () -> ST s Int
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ STArray# s e -> Int -> STArray# s e -> Int -> Int -> ST s ()
forall (m :: * -> *) l e.
LinearM m l e =>
l -> Int -> l -> Int -> Int -> m ()
copyTo STArray# s e
arr Int
0 STArray# s e
marr Int
i Int
c
ST s Int -> ST s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ST s Int -> ST s ()) -> ST s Int -> ST s ()
forall a b. (a -> b) -> a -> b
$ (STArray# s e -> ST s Int -> ST s Int)
-> ST s Int -> f (STArray# s e) -> ST s Int
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((Int -> ST s Int) -> ST s Int -> ST s Int
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
(=<<) ((Int -> ST s Int) -> ST s Int -> ST s Int)
-> (STArray# s e -> Int -> ST s Int)
-> STArray# s e
-> ST s Int
-> ST s Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# s e -> Int -> ST s Int
writer) (Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
0) f (STArray# s e)
ess
STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
marr
where
n :: Int
n = (STArray# s e -> Int -> Int) -> Int -> f (STArray# s e) -> Int
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr' (Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) (Int -> Int -> Int)
-> (STArray# s e -> Int) -> STArray# s e -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# s e -> Int
forall b i. Bordered b i => b -> Int
sizeOf) Int
0 f (STArray# s e)
ess
ofoldrM :: (Int -> e -> r -> ST s r) -> r -> STArray# s e -> ST s r
ofoldrM Int -> e -> r -> ST s r
f r
base = \ arr :: STArray# s e
arr@(STArray# Int
n Int
_ MutableArray# s e
_) ->
let go :: Int -> ST s r
go Int
i = Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> ST s r -> ST s r -> ST s r
forall a. Bool -> a -> a -> a
? r -> ST s r
forall (m :: * -> *) a. Monad m => a -> m a
return r
base (ST s r -> ST s r) -> ST s r -> ST s r
forall a b. (a -> b) -> a -> b
$ (STArray# s e
arr STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i) ST s e -> ST s r -> (e -> r -> ST s r) -> ST s r
forall (m :: * -> *) a b c.
Monad m =>
m a -> m b -> (a -> b -> m c) -> m c
>>=<< Int -> ST s r
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) ((e -> r -> ST s r) -> ST s r) -> (e -> r -> ST s r) -> ST s r
forall a b. (a -> b) -> a -> b
$ Int -> e -> r -> ST s r
f Int
i
in Int -> ST s r
go Int
0
ofoldlM :: (Int -> r -> e -> ST s r) -> r -> STArray# s e -> ST s r
ofoldlM Int -> r -> e -> ST s r
f r
base = \ arr :: STArray# s e
arr@(STArray# Int
n Int
_ MutableArray# s e
_) ->
let go :: Int -> ST s r
go Int
i = -Int
1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> ST s r -> ST s r -> ST s r
forall a. Bool -> a -> a -> a
? r -> ST s r
forall (m :: * -> *) a. Monad m => a -> m a
return r
base (ST s r -> ST s r) -> ST s r -> ST s r
forall a b. (a -> b) -> a -> b
$ Int -> ST s r
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ST s r -> ST s e -> (r -> e -> ST s r) -> ST s r
forall (m :: * -> *) a b c.
Monad m =>
m a -> m b -> (a -> b -> m c) -> m c
>>=<< (STArray# s e
arr STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i) ((r -> e -> ST s r) -> ST s r) -> (r -> e -> ST s r) -> ST s r
forall a b. (a -> b) -> a -> b
$ Int -> r -> e -> ST s r
f Int
i
in Int -> ST s r
go (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
foldrM :: (e -> r -> ST s r) -> r -> STArray# s e -> ST s r
foldrM e -> r -> ST s r
f r
base = \ arr :: STArray# s e
arr@(STArray# Int
n Int
_ MutableArray# s e
_) ->
let go :: Int -> ST s r
go Int
i = Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> ST s r -> ST s r -> ST s r
forall a. Bool -> a -> a -> a
? r -> ST s r
forall (m :: * -> *) a. Monad m => a -> m a
return r
base (ST s r -> ST s r) -> ST s r -> ST s r
forall a b. (a -> b) -> a -> b
$ (STArray# s e
arr STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i) ST s e -> ST s r -> (e -> r -> ST s r) -> ST s r
forall (m :: * -> *) a b c.
Monad m =>
m a -> m b -> (a -> b -> m c) -> m c
>>=<< Int -> ST s r
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) ((e -> r -> ST s r) -> ST s r) -> (e -> r -> ST s r) -> ST s r
forall a b. (a -> b) -> a -> b
$ e -> r -> ST s r
f
in Int -> ST s r
go Int
0
foldlM :: (r -> e -> ST s r) -> r -> STArray# s e -> ST s r
foldlM r -> e -> ST s r
f r
base = \ arr :: STArray# s e
arr@(STArray# Int
n Int
_ MutableArray# s e
_) ->
let go :: Int -> ST s r
go Int
i = -Int
1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> ST s r -> ST s r -> ST s r
forall a. Bool -> a -> a -> a
? r -> ST s r
forall (m :: * -> *) a. Monad m => a -> m a
return r
base (ST s r -> ST s r) -> ST s r -> ST s r
forall a b. (a -> b) -> a -> b
$ Int -> ST s r
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ST s r -> ST s e -> (r -> e -> ST s r) -> ST s r
forall (m :: * -> *) a b c.
Monad m =>
m a -> m b -> (a -> b -> m c) -> m c
>>=<< (STArray# s e
arr STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i) ((r -> e -> ST s r) -> ST s r) -> (r -> e -> ST s r) -> ST s r
forall a b. (a -> b) -> a -> b
$ r -> e -> ST s r
f
in Int -> ST s r
go (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
instance SplitM (ST s) (STArray# s e) e
where
takeM :: Int -> STArray# s e -> ST s (STArray# s e)
takeM Int
n es :: STArray# s e
es@(STArray# Int
c Int
o MutableArray# s e
marr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
es
| Bool
True = STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
n Int
o MutableArray# s e
marr#)
dropM :: Int -> STArray# s e -> ST s (STArray# s e)
dropM Int
n es :: STArray# s e
es@(STArray# Int
c Int
o MutableArray# s e
marr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
es
| Bool
True = STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) MutableArray# s e
marr#)
keepM :: Int -> STArray# s e -> ST s (STArray# s e)
keepM Int
n es :: STArray# s e
es@(STArray# Int
c Int
o MutableArray# s e
marr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
es
| Bool
True = STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
n (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o) MutableArray# s e
marr#)
sansM :: Int -> STArray# s e -> ST s (STArray# s e)
sansM Int
n es :: STArray# s e
es@(STArray# Int
c Int
o MutableArray# s e
marr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
es
| Bool
True = STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) Int
o MutableArray# s e
marr#)
splitM :: Int -> STArray# s e -> ST s (STArray# s e, STArray# s e)
splitM Int
n es :: STArray# s e
es@(STArray# Int
c Int
o MutableArray# s e
marr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = do STArray# s e
e' <- ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull; (STArray# s e, STArray# s e) -> ST s (STArray# s e, STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (STArray# s e
e', STArray# s e
es)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = do STArray# s e
e' <- ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull; (STArray# s e, STArray# s e) -> ST s (STArray# s e, STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (STArray# s e
es, STArray# s e
e')
| Bool
True = (STArray# s e, STArray# s e) -> ST s (STArray# s e, STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
n Int
o MutableArray# s e
marr#, Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) MutableArray# s e
marr#)
divideM :: Int -> STArray# s e -> ST s (STArray# s e, STArray# s e)
divideM Int
n es :: STArray# s e
es@(STArray# Int
c Int
o MutableArray# s e
marr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = do STArray# s e
e' <- ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull; (STArray# s e, STArray# s e) -> ST s (STArray# s e, STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (STArray# s e
es, STArray# s e
e')
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = do STArray# s e
e' <- ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull; (STArray# s e, STArray# s e) -> ST s (STArray# s e, STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (STArray# s e
e', STArray# s e
es)
| Bool
True = (STArray# s e, STArray# s e) -> ST s (STArray# s e, STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
n (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o) MutableArray# s e
marr#, Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) Int
o MutableArray# s e
marr#)
prefixM :: (e -> Bool) -> STArray# s e -> ST s Int
prefixM e -> Bool
p es :: STArray# s e
es@(STArray# Int
c Int
_ MutableArray# s e
_) =
let go :: Int -> ST s Int
go Int
i = Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c Bool -> ST s Int -> ST s Int -> ST s Int
forall a. Bool -> a -> a -> a
? Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
c (ST s Int -> ST s Int) -> ST s Int -> ST s Int
forall a b. (a -> b) -> a -> b
$ do e
e <- STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i; e -> Bool
p e
e Bool -> ST s Int -> ST s Int -> ST s Int
forall a. Bool -> a -> a -> a
? Int -> ST s Int
go (Int -> Int
forall a. Enum a => a -> a
succ Int
i) (ST s Int -> ST s Int) -> ST s Int -> ST s Int
forall a b. (a -> b) -> a -> b
$ Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
i
in Int -> ST s Int
go Int
0
suffixM :: (e -> Bool) -> STArray# s e -> ST s Int
suffixM e -> Bool
p es :: STArray# s e
es@(STArray# Int
c Int
_ MutableArray# s e
_) =
let go :: Int -> ST s Int
go Int
i = Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 Bool -> ST s Int -> ST s Int -> ST s Int
forall a. Bool -> a -> a -> a
? Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
c (ST s Int -> ST s Int) -> ST s Int -> ST s Int
forall a b. (a -> b) -> a -> b
$ do e
e <- STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i; e -> Bool
p e
e Bool -> ST s Int -> ST s Int -> ST s Int
forall a. Bool -> a -> a -> a
? Int -> ST s Int
go (Int -> Int
forall a. Enum a => a -> a
pred Int
i) (ST s Int -> ST s Int) -> ST s Int -> ST s Int
forall a b. (a -> b) -> a -> b
$ Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
in Int -> ST s Int
go (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1))
mprefix :: (e -> ST s Bool) -> STArray# s e -> ST s Int
mprefix e -> ST s Bool
p es :: STArray# s e
es@(STArray# Int
c Int
_ MutableArray# s e
_) =
let go :: Int -> ST s Int
go Int
i = Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c Bool -> ST s Int -> ST s Int -> ST s Int
forall a. Bool -> a -> a -> a
? Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
c (ST s Int -> ST s Int) -> ST s Int -> ST s Int
forall a b. (a -> b) -> a -> b
$ do e
e <- STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i; e -> ST s Bool
p e
e ST s Bool -> ST s Int -> ST s Int -> ST s Int
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
?^ Int -> ST s Int
go (Int -> Int
forall a. Enum a => a -> a
succ Int
1) (ST s Int -> ST s Int) -> ST s Int -> ST s Int
forall a b. (a -> b) -> a -> b
$ Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
i
in Int -> ST s Int
go Int
0
msuffix :: (e -> ST s Bool) -> STArray# s e -> ST s Int
msuffix e -> ST s Bool
p es :: STArray# s e
es@(STArray# Int
c Int
_ MutableArray# s e
_) =
let go :: Int -> ST s Int
go Int
i = Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 Bool -> ST s Int -> ST s Int -> ST s Int
forall a. Bool -> a -> a -> a
? Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
c (ST s Int -> ST s Int) -> ST s Int -> ST s Int
forall a b. (a -> b) -> a -> b
$ do e
e <- STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i; e -> ST s Bool
p e
e ST s Bool -> ST s Int -> ST s Int -> ST s Int
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
?^ Int -> ST s Int
go (Int -> Int
forall a. Enum a => a -> a
pred Int
i) (ST s Int -> ST s Int) -> ST s Int -> ST s Int
forall a b. (a -> b) -> a -> b
$ Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
in Int -> ST s Int
go (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1))
instance MapM (ST s) (STArray# s e) Int e
where
newMap' :: e -> [(Int, e)] -> ST s (STArray# s e)
newMap' e
defvalue [(Int, e)]
ascs = (Int, Int) -> e -> [(Int, e)] -> ST s (STArray# s e)
forall (m :: * -> *) v i e.
IndexedM m v i e =>
(i, i) -> e -> [(i, e)] -> m v
fromAssocs' ([(Int, e)] -> (Int, Int)
forall a b. Ord a => [(a, b)] -> (a, a)
ascsBounds [(Int, e)]
ascs) e
defvalue [(Int, e)]
ascs
>! :: STArray# s e -> Int -> ST s e
(>!) = STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
(!#>)
overwrite :: STArray# s e -> [(Int, e)] -> ST s (STArray# s e)
overwrite es :: STArray# s e
es@(STArray# Int
c Int
_ MutableArray# s e
_) [(Int, e)]
ascs =
let ies :: [(Int, e)]
ies = ((Int, e) -> Bool) -> [(Int, e)] -> [(Int, e)]
forall l e. Linear l e => (e -> Bool) -> l -> l
filter ((Int, Int) -> Int -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Int -> Bool) -> ((Int, e) -> Int) -> (Int, e) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, e) -> Int
forall a b. (a, b) -> a
fst) [(Int, e)]
ascs
in ((Int, e) -> ST s ()) -> [(Int, e)] -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((Int -> e -> ST s ()) -> (Int, e) -> ST s ()
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((Int -> e -> ST s ()) -> (Int, e) -> ST s ())
-> (Int -> e -> ST s ()) -> (Int, e) -> ST s ()
forall a b. (a -> b) -> a -> b
$ STArray# s e -> Int -> e -> ST s ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM STArray# s e
es) [(Int, e)]
ies ST s () -> ST s (STArray# s e) -> ST s (STArray# s e)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
es
kfoldrM :: (Int -> e -> acc -> ST s acc) -> acc -> STArray# s e -> ST s acc
kfoldrM = (Int -> e -> acc -> ST s acc) -> acc -> STArray# s e -> ST s acc
forall (m :: * -> *) l e r.
LinearM m l e =>
(Int -> e -> r -> m r) -> r -> l -> m r
ofoldrM
kfoldlM :: (Int -> acc -> e -> ST s acc) -> acc -> STArray# s e -> ST s acc
kfoldlM = (Int -> acc -> e -> ST s acc) -> acc -> STArray# s e -> ST s acc
forall (m :: * -> *) l e r.
LinearM m l e =>
(Int -> r -> e -> m r) -> r -> l -> m r
ofoldlM
instance IndexedM (ST s) (STArray# s e) Int e
where
fromAssocs' :: (Int, Int) -> e -> [(Int, e)] -> ST s (STArray# s e)
fromAssocs' (Int, Int)
bnds e
defvalue [(Int, e)]
ascs = (Int, Int) -> Int
forall i. Index i => (i, i) -> Int
size (Int, Int)
bnds Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
`filled` e
defvalue ST s (STArray# s e)
-> (STArray# s e -> ST s (STArray# s e)) -> ST s (STArray# s e)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (STArray# s e -> [(Int, e)] -> ST s (STArray# s e)
forall (m :: * -> *) map key e.
MapM m map key e =>
map -> [(key, e)] -> m map
`overwrite` [(Int, e)]
ascs)
{-# INLINE writeM' #-}
writeM' :: STArray# s e -> Int -> e -> ST s ()
writeM' (STArray# Int
_ (I# Int#
o#) MutableArray# s e
marr#) = \ (I# Int#
i#) e
e -> STRep s () -> ST s ()
forall s a. STRep s a -> ST s a
ST (STRep s () -> ST s ()) -> STRep s () -> ST s ()
forall a b. (a -> b) -> a -> b
$
\ State# s
s1# -> case MutableArray# s e -> Int# -> e -> State# s -> State# s
forall d a. MutableArray# d a -> Int# -> a -> State# d -> State# d
writeArray# MutableArray# s e
marr# (Int#
o# Int# -> Int# -> Int#
+# Int#
i#) e
e State# s
s1# of State# s
s2# -> (# State# s
s2#, () #)
fromIndexed' :: v' -> ST s (STArray# s e)
fromIndexed' v'
es = do
let n :: Int
n = v' -> Int
forall b i. Bordered b i => b -> Int
sizeOf v'
es
STArray# s e
copy <- Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
n (String -> e
forall a. String -> a
unreachEx String
"fromIndexed'")
[Int] -> (Int -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \ Int
i -> STArray# s e -> Int -> e -> ST s ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM STArray# s e
copy Int
i (v'
es v' -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^ Int
i)
STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
copy
fromIndexedM :: v' -> ST s (STArray# s e)
fromIndexedM v'
es = do
Int
n <- v' -> ST s Int
forall (m :: * -> *) b i. BorderedM m b i => b -> m Int
getSizeOf v'
es
STArray# s e
copy <- Int -> e -> ST s (STArray# s e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
n (String -> e
forall a. String -> a
unreachEx String
"fromIndexedM")
[Int] -> (Int -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \ Int
i -> v'
es v' -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i ST s e -> (e -> ST s ()) -> ST s ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STArray# s e -> Int -> e -> ST s ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM STArray# s e
copy Int
i
STArray# s e -> ST s (STArray# s e)
forall (m :: * -> *) a. Monad m => a -> m a
return STArray# s e
copy
instance SortM (ST s) (STArray# s e) e
where
sortedMBy :: (e -> e -> Bool) -> STArray# s e -> ST s Bool
sortedMBy e -> e -> Bool
f es :: STArray# s e
es@(STArray# Int
n Int
_ MutableArray# s e
_) =
let go :: Int -> e -> ST s Bool
go Int
i e
e1 = Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n Bool -> ST s Bool -> ST s Bool -> ST s Bool
forall a. Bool -> a -> a -> a
? Bool -> ST s Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True (ST s Bool -> ST s Bool) -> ST s Bool -> ST s Bool
forall a b. (a -> b) -> a -> b
$ do e
e2 <- STArray# s e
es STArray# s e -> Int -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i; e
e1 e -> e -> Bool
`f` e
e2 Bool -> ST s Bool -> ST s Bool -> ST s Bool
forall a. Bool -> a -> a -> a
? Int -> e -> ST s Bool
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) e
e2 (ST s Bool -> ST s Bool) -> ST s Bool -> ST s Bool
forall a b. (a -> b) -> a -> b
$ Bool -> ST s Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
in Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
2 Bool -> ST s Bool -> ST s Bool -> ST s Bool
forall a. Bool -> a -> a -> a
? Bool -> ST s Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True (ST s Bool -> ST s Bool) -> ST s Bool -> ST s Bool
forall a b. (a -> b) -> a -> b
$ Int -> e -> ST s Bool
go Int
1 (e -> ST s Bool) -> ST s e -> ST s Bool
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< STArray# s e -> ST s e
forall (m :: * -> *) l e. LinearM m l e => l -> m e
getHead STArray# s e
es
sortMBy :: Compare e -> STArray# s e -> ST s ()
sortMBy = Compare e -> STArray# s e -> ST s ()
forall (m :: * -> *) v e i.
(LinearM m v e, BorderedM m v i) =>
Compare e -> v -> m ()
timSortBy
newtype MIOArray# (io :: Type -> Type) e = MIOArray# (STArray# RealWorld e)
deriving ( MIOArray# io e -> MIOArray# io e -> Bool
(MIOArray# io e -> MIOArray# io e -> Bool)
-> (MIOArray# io e -> MIOArray# io e -> Bool)
-> Eq (MIOArray# io e)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (io :: * -> *) e. MIOArray# io e -> MIOArray# io e -> Bool
/= :: MIOArray# io e -> MIOArray# io e -> Bool
$c/= :: forall (io :: * -> *) e. MIOArray# io e -> MIOArray# io e -> Bool
== :: MIOArray# io e -> MIOArray# io e -> Bool
$c== :: forall (io :: * -> *) e. MIOArray# io e -> MIOArray# io e -> Bool
Eq )
type IOArray# = MIOArray# IO
{-# INLINE unpack #-}
unpack :: MIOArray# io e -> STArray# RealWorld e
unpack :: MIOArray# io e -> STArray# RealWorld e
unpack = MIOArray# io e -> STArray# RealWorld e
coerce
{-# INLINE pack #-}
pack :: (MonadIO io) => ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack :: ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack = ST RealWorld (MIOArray# io e) -> io (MIOArray# io e)
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld (MIOArray# io e) -> io (MIOArray# io e))
-> (ST RealWorld (STArray# RealWorld e)
-> ST RealWorld (MIOArray# io e))
-> ST RealWorld (STArray# RealWorld e)
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ST RealWorld (STArray# RealWorld e)
-> ST RealWorld (MIOArray# io e)
coerce
instance Estimate (MIOArray# io e)
where
<==> :: Compare (MIOArray# io e)
(<==>) = Compare Int -> (MIOArray# io e -> Int) -> Compare (MIOArray# io e)
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Compare Int
forall o. Ord o => Compare o
(<=>) MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.<=. :: MIOArray# io e -> MIOArray# io e -> Bool
(.<=.) = (Int -> Int -> Bool)
-> (MIOArray# io e -> Int)
-> MIOArray# io e
-> MIOArray# io e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<=) MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.>=. :: MIOArray# io e -> MIOArray# io e -> Bool
(.>=.) = (Int -> Int -> Bool)
-> (MIOArray# io e -> Int)
-> MIOArray# io e
-> MIOArray# io e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=) MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.>. :: MIOArray# io e -> MIOArray# io e -> Bool
(.>.) = (Int -> Int -> Bool)
-> (MIOArray# io e -> Int)
-> MIOArray# io e
-> MIOArray# io e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>) MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.<. :: MIOArray# io e -> MIOArray# io e -> Bool
(.<.) = (Int -> Int -> Bool)
-> (MIOArray# io e -> Int)
-> MIOArray# io e
-> MIOArray# io e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
<.=> :: MIOArray# io e -> Int -> Ordering
(<.=>) = Compare Int
forall o. Ord o => Compare o
(<=>) Compare Int
-> (MIOArray# io e -> Int) -> MIOArray# io e -> Int -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.>= :: MIOArray# io e -> Int -> Bool
(.>=) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=) (Int -> Int -> Bool)
-> (MIOArray# io e -> Int) -> MIOArray# io e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.<= :: MIOArray# io e -> Int -> Bool
(.<=) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<=) (Int -> Int -> Bool)
-> (MIOArray# io e -> Int) -> MIOArray# io e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.> :: MIOArray# io e -> Int -> Bool
(.>) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>) (Int -> Int -> Bool)
-> (MIOArray# io e -> Int) -> MIOArray# io e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
.< :: MIOArray# io e -> Int -> Bool
(.<) = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) (Int -> Int -> Bool)
-> (MIOArray# io e -> Int) -> MIOArray# io e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
instance Bordered (MIOArray# io e) Int
where
lower :: MIOArray# io e -> Int
lower MIOArray# io e
_ = Int
0
sizeOf :: MIOArray# io e -> Int
sizeOf (MIOArray# (STArray# Int
c Int
_ MutableArray# RealWorld e
_)) = Int
c
upper :: MIOArray# io e -> Int
upper (MIOArray# (STArray# Int
c Int
_ MutableArray# RealWorld e
_)) = Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
bounds :: MIOArray# io e -> (Int, Int)
bounds (MIOArray# (STArray# Int
c Int
_ MutableArray# RealWorld e
_)) = (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
indices :: MIOArray# io e -> [Int]
indices (MIOArray# (STArray# Int
c Int
_ MutableArray# RealWorld e
_)) = [Int
0 .. Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
indexOf :: MIOArray# io e -> Int -> Int
indexOf (MIOArray# (STArray# Int
c Int
_ MutableArray# RealWorld e
_)) = (Int, Int) -> Int -> Int
forall i. Index i => (i, i) -> Int -> i
index (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
offsetOf :: MIOArray# io e -> Int -> Int
offsetOf (MIOArray# (STArray# Int
c Int
_ MutableArray# RealWorld e
_)) = (Int, Int) -> Int -> Int
forall i. Index i => (i, i) -> i -> Int
offset (Int
0, Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
indexIn :: MIOArray# io e -> Int -> Bool
indexIn (MIOArray# (STArray# Int
c Int
_ MutableArray# RealWorld e
_)) = \ Int
i -> Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
c
instance (MonadIO io) => BorderedM io (MIOArray# io e) Int
where
getIndexOf :: MIOArray# io e -> Int -> io Int
getIndexOf = Int -> io Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> io Int)
-> (MIOArray# io e -> Int -> Int)
-> MIOArray# io e
-> Int
-> io Int
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... STArray# RealWorld e -> Int -> Int
forall b i. Bordered b i => b -> Int -> i
indexOf (STArray# RealWorld e -> Int -> Int)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> Int
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
getIndices :: MIOArray# io e -> io [Int]
getIndices = [Int] -> io [Int]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Int] -> io [Int])
-> (MIOArray# io e -> [Int]) -> MIOArray# io e -> io [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> [Int]
forall b i. Bordered b i => b -> [i]
indices (STArray# RealWorld e -> [Int])
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
getSizeOf :: MIOArray# io e -> io Int
getSizeOf = Int -> io Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> io Int)
-> (MIOArray# io e -> Int) -> MIOArray# io e -> io Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> Int
forall b i. Bordered b i => b -> Int
sizeOf (STArray# RealWorld e -> Int)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
getBounds :: MIOArray# io e -> io (Int, Int)
getBounds = (Int, Int) -> io (Int, Int)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Int, Int) -> io (Int, Int))
-> (MIOArray# io e -> (Int, Int))
-> MIOArray# io e
-> io (Int, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> (Int, Int)
forall b i. Bordered b i => b -> (i, i)
bounds (STArray# RealWorld e -> (Int, Int))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> (Int, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
getUpper :: MIOArray# io e -> io Int
getUpper = Int -> io Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> io Int)
-> (MIOArray# io e -> Int) -> MIOArray# io e -> io Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> Int
forall b i. Bordered b i => b -> i
upper (STArray# RealWorld e -> Int)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
getLower :: MIOArray# io e -> io Int
getLower MIOArray# io e
_ = Int -> io Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
0
instance (MonadIO io) => LinearM io (MIOArray# io e) e
where
newNull :: io (MIOArray# io e)
newNull = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
singleM :: e -> io (MIOArray# io e)
singleM = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (e -> ST RealWorld (STArray# RealWorld e))
-> e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => e -> m l
singleM
nowNull :: MIOArray# io e -> io Bool
nowNull = ST RealWorld Bool -> io Bool
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld Bool -> io Bool)
-> (MIOArray# io e -> ST RealWorld Bool)
-> MIOArray# io e
-> io Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> ST RealWorld Bool
forall (m :: * -> *) l e. LinearM m l e => l -> m Bool
nowNull (STArray# RealWorld e -> ST RealWorld Bool)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
getHead :: MIOArray# io e -> io e
getHead = ST RealWorld e -> io e
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld e -> io e)
-> (MIOArray# io e -> ST RealWorld e) -> MIOArray# io e -> io e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> ST RealWorld e
forall (m :: * -> *) l e. LinearM m l e => l -> m e
getHead (STArray# RealWorld e -> ST RealWorld e)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
getLast :: MIOArray# io e -> io e
getLast = ST RealWorld e -> io e
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld e -> io e)
-> (MIOArray# io e -> ST RealWorld e) -> MIOArray# io e -> io e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> ST RealWorld e
forall (m :: * -> *) l e. LinearM m l e => l -> m e
getLast (STArray# RealWorld e -> ST RealWorld e)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
prepend :: e -> MIOArray# io e -> io (MIOArray# io e)
prepend e
e = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (MIOArray# io e -> ST RealWorld (STArray# RealWorld e))
-> MIOArray# io e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => e -> l -> m l
prepend e
e (STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld (STArray# RealWorld e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
append :: MIOArray# io e -> e -> io (MIOArray# io e)
append MIOArray# io e
es = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (e -> ST RealWorld (STArray# RealWorld e))
-> e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => l -> e -> m l
append (MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack MIOArray# io e
es)
newLinear :: [e] -> io (MIOArray# io e)
newLinear = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> ([e] -> ST RealWorld (STArray# RealWorld e))
-> [e]
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [e] -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => [e] -> m l
newLinear
newLinearN :: Int -> [e] -> io (MIOArray# io e)
newLinearN = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (Int -> [e] -> ST RealWorld (STArray# RealWorld e))
-> Int
-> [e]
-> io (MIOArray# io e)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... Int -> [e] -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => Int -> [e] -> m l
newLinearN
fromFoldableM :: f e -> io (MIOArray# io e)
fromFoldableM = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (f e -> ST RealWorld (STArray# RealWorld e))
-> f e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e (f :: * -> *).
(LinearM m l e, Foldable f) =>
f e -> m l
fromFoldableM
writeM :: MIOArray# io e -> Int -> e -> io ()
writeM = MIOArray# io e -> Int -> e -> io ()
forall (m :: * -> *) v i e. IndexedM m v i e => v -> i -> e -> m ()
writeM'
!#> :: MIOArray# io e -> Int -> io e
(!#>) = ST RealWorld e -> io e
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld e -> io e)
-> (MIOArray# io e -> Int -> ST RealWorld e)
-> MIOArray# io e
-> Int
-> io e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... STArray# RealWorld e -> Int -> ST RealWorld e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
(!#>) (STArray# RealWorld e -> Int -> ST RealWorld e)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> Int
-> ST RealWorld e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
copied :: MIOArray# io e -> io (MIOArray# io e)
copied = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (MIOArray# io e -> ST RealWorld (STArray# RealWorld e))
-> MIOArray# io e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => l -> m l
copied (STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld (STArray# RealWorld e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
reversed :: MIOArray# io e -> io (MIOArray# io e)
reversed = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (MIOArray# io e -> ST RealWorld (STArray# RealWorld e))
-> MIOArray# io e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => l -> m l
reversed (STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld (STArray# RealWorld e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
getLeft :: MIOArray# io e -> io [e]
getLeft = ST RealWorld [e] -> io [e]
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld [e] -> io [e])
-> (MIOArray# io e -> ST RealWorld [e]) -> MIOArray# io e -> io [e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> ST RealWorld [e]
forall (m :: * -> *) l e. LinearM m l e => l -> m [e]
getLeft (STArray# RealWorld e -> ST RealWorld [e])
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld [e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
getRight :: MIOArray# io e -> io [e]
getRight = ST RealWorld [e] -> io [e]
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld [e] -> io [e])
-> (MIOArray# io e -> ST RealWorld [e]) -> MIOArray# io e -> io [e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> ST RealWorld [e]
forall (m :: * -> *) l e. LinearM m l e => l -> m [e]
getRight (STArray# RealWorld e -> ST RealWorld [e])
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld [e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
copied' :: MIOArray# io e -> Int -> Int -> io (MIOArray# io e)
copied' MIOArray# io e
es = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (Int -> Int -> ST RealWorld (STArray# RealWorld e))
-> Int
-> Int
-> io (MIOArray# io e)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... STArray# RealWorld e
-> Int -> Int -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> Int -> m l
copied' (MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack MIOArray# io e
es)
merged :: f (MIOArray# io e) -> io (MIOArray# io e)
merged = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (f (MIOArray# io e) -> ST RealWorld (STArray# RealWorld e))
-> f (MIOArray# io e)
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [STArray# RealWorld e] -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e (f :: * -> *).
(LinearM m l e, Foldable f) =>
f l -> m l
merged ([STArray# RealWorld e] -> ST RealWorld (STArray# RealWorld e))
-> (f (MIOArray# io e) -> [STArray# RealWorld e])
-> f (MIOArray# io e)
-> ST RealWorld (STArray# RealWorld e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MIOArray# io e
-> [STArray# RealWorld e] -> [STArray# RealWorld e])
-> [STArray# RealWorld e]
-> f (MIOArray# io e)
-> [STArray# RealWorld e]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((:) (STArray# RealWorld e
-> [STArray# RealWorld e] -> [STArray# RealWorld e])
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> [STArray# RealWorld e]
-> [STArray# RealWorld e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack) []
filled :: Int -> e -> io (MIOArray# io e)
filled = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (Int -> e -> ST RealWorld (STArray# RealWorld e))
-> Int
-> e
-> io (MIOArray# io e)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... Int -> e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled
copyTo :: MIOArray# io e -> Int -> MIOArray# io e -> Int -> Int -> io ()
copyTo MIOArray# io e
src Int
so MIOArray# io e
trg Int
to = ST RealWorld () -> io ()
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld () -> io ())
-> (Int -> ST RealWorld ()) -> Int -> io ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e
-> Int -> STArray# RealWorld e -> Int -> Int -> ST RealWorld ()
forall (m :: * -> *) l e.
LinearM m l e =>
l -> Int -> l -> Int -> Int -> m ()
copyTo (MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack MIOArray# io e
src) Int
so (MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack MIOArray# io e
trg) Int
to
ofoldrM :: (Int -> e -> r -> io r) -> r -> MIOArray# io e -> io r
ofoldrM Int -> e -> r -> io r
f r
base = \ arr :: MIOArray# io e
arr@(MIOArray# (STArray# Int
n Int
_ MutableArray# RealWorld e
_)) ->
let go :: Int -> io r
go Int
i = Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> io r -> io r -> io r
forall a. Bool -> a -> a -> a
? r -> io r
forall (m :: * -> *) a. Monad m => a -> m a
return r
base (io r -> io r) -> io r -> io r
forall a b. (a -> b) -> a -> b
$ (MIOArray# io e
arr MIOArray# io e -> Int -> io e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i) io e -> io r -> (e -> r -> io r) -> io r
forall (m :: * -> *) a b c.
Monad m =>
m a -> m b -> (a -> b -> m c) -> m c
>>=<< Int -> io r
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) ((e -> r -> io r) -> io r) -> (e -> r -> io r) -> io r
forall a b. (a -> b) -> a -> b
$ Int -> e -> r -> io r
f Int
i
in Int -> io r
go Int
0
ofoldlM :: (Int -> r -> e -> io r) -> r -> MIOArray# io e -> io r
ofoldlM Int -> r -> e -> io r
f r
base = \ arr :: MIOArray# io e
arr@(MIOArray# (STArray# Int
n Int
_ MutableArray# RealWorld e
_)) ->
let go :: Int -> io r
go Int
i = -Int
1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> io r -> io r -> io r
forall a. Bool -> a -> a -> a
? r -> io r
forall (m :: * -> *) a. Monad m => a -> m a
return r
base (io r -> io r) -> io r -> io r
forall a b. (a -> b) -> a -> b
$ Int -> io r
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) io r -> io e -> (r -> e -> io r) -> io r
forall (m :: * -> *) a b c.
Monad m =>
m a -> m b -> (a -> b -> m c) -> m c
>>=<< (MIOArray# io e
arr MIOArray# io e -> Int -> io e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i) ((r -> e -> io r) -> io r) -> (r -> e -> io r) -> io r
forall a b. (a -> b) -> a -> b
$ Int -> r -> e -> io r
f Int
i
in Int -> io r
go (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
foldrM :: (e -> r -> io r) -> r -> MIOArray# io e -> io r
foldrM e -> r -> io r
f r
base MIOArray# io e
arr =
let go :: Int -> io r
go Int
i = MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf MIOArray# io e
arr Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> io r -> io r -> io r
forall a. Bool -> a -> a -> a
? r -> io r
forall (m :: * -> *) a. Monad m => a -> m a
return r
base (io r -> io r) -> io r -> io r
forall a b. (a -> b) -> a -> b
$ (MIOArray# io e
arr MIOArray# io e -> Int -> io e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i) io e -> io r -> (e -> r -> io r) -> io r
forall (m :: * -> *) a b c.
Monad m =>
m a -> m b -> (a -> b -> m c) -> m c
>>=<< Int -> io r
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) ((e -> r -> io r) -> io r) -> (e -> r -> io r) -> io r
forall a b. (a -> b) -> a -> b
$ e -> r -> io r
f
in Int -> io r
go Int
0
foldlM :: (r -> e -> io r) -> r -> MIOArray# io e -> io r
foldlM r -> e -> io r
f r
base MIOArray# io e
arr =
let go :: Int -> io r
go Int
i = -Int
1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i Bool -> io r -> io r -> io r
forall a. Bool -> a -> a -> a
? r -> io r
forall (m :: * -> *) a. Monad m => a -> m a
return r
base (io r -> io r) -> io r -> io r
forall a b. (a -> b) -> a -> b
$ Int -> io r
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) io r -> io e -> (r -> e -> io r) -> io r
forall (m :: * -> *) a b c.
Monad m =>
m a -> m b -> (a -> b -> m c) -> m c
>>=<< (MIOArray# io e
arr MIOArray# io e -> Int -> io e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i) ((r -> e -> io r) -> io r) -> (r -> e -> io r) -> io r
forall a b. (a -> b) -> a -> b
$ r -> e -> io r
f
in Int -> io r
go (MIOArray# io e -> Int
forall b i. Bordered b i => b -> Int
sizeOf MIOArray# io e
arr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
instance (MonadIO io) => SplitM io (MIOArray# io e) e
where
takeM :: Int -> MIOArray# io e -> io (MIOArray# io e)
takeM Int
n = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (MIOArray# io e -> ST RealWorld (STArray# RealWorld e))
-> MIOArray# io e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m s
takeM Int
n (STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld (STArray# RealWorld e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
dropM :: Int -> MIOArray# io e -> io (MIOArray# io e)
dropM Int
n = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (MIOArray# io e -> ST RealWorld (STArray# RealWorld e))
-> MIOArray# io e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m s
dropM Int
n (STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld (STArray# RealWorld e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
keepM :: Int -> MIOArray# io e -> io (MIOArray# io e)
keepM Int
n = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (MIOArray# io e -> ST RealWorld (STArray# RealWorld e))
-> MIOArray# io e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m s
keepM Int
n (STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld (STArray# RealWorld e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
sansM :: Int -> MIOArray# io e -> io (MIOArray# io e)
sansM Int
n = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (MIOArray# io e -> ST RealWorld (STArray# RealWorld e))
-> MIOArray# io e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m s
sansM Int
n (STArray# RealWorld e -> ST RealWorld (STArray# RealWorld e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld (STArray# RealWorld e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
prefixM :: (e -> Bool) -> MIOArray# io e -> io Int
prefixM e -> Bool
f = ST RealWorld Int -> io Int
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld Int -> io Int)
-> (MIOArray# io e -> ST RealWorld Int) -> MIOArray# io e -> io Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> Bool) -> STArray# RealWorld e -> ST RealWorld Int
forall (m :: * -> *) s e. SplitM m s e => (e -> Bool) -> s -> m Int
prefixM e -> Bool
f (STArray# RealWorld e -> ST RealWorld Int)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
suffixM :: (e -> Bool) -> MIOArray# io e -> io Int
suffixM e -> Bool
f = ST RealWorld Int -> io Int
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld Int -> io Int)
-> (MIOArray# io e -> ST RealWorld Int) -> MIOArray# io e -> io Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> Bool) -> STArray# RealWorld e -> ST RealWorld Int
forall (m :: * -> *) s e. SplitM m s e => (e -> Bool) -> s -> m Int
suffixM e -> Bool
f (STArray# RealWorld e -> ST RealWorld Int)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
mprefix :: (e -> io Bool) -> MIOArray# io e -> io Int
mprefix e -> io Bool
p es :: MIOArray# io e
es@(MIOArray# (STArray# Int
c Int
_ MutableArray# RealWorld e
_)) =
let go :: Int -> io Int
go Int
i = Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c Bool -> io Int -> io Int -> io Int
forall a. Bool -> a -> a -> a
? Int -> io Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
c (io Int -> io Int) -> io Int -> io Int
forall a b. (a -> b) -> a -> b
$ do e
e <- MIOArray# io e
es MIOArray# io e -> Int -> io e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i; e -> io Bool
p e
e io Bool -> io Int -> io Int -> io Int
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
?^ Int -> io Int
go (Int -> Int
forall a. Enum a => a -> a
succ Int
1) (io Int -> io Int) -> io Int -> io Int
forall a b. (a -> b) -> a -> b
$ Int -> io Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
i
in Int -> io Int
go Int
0
msuffix :: (e -> io Bool) -> MIOArray# io e -> io Int
msuffix e -> io Bool
p es :: MIOArray# io e
es@(MIOArray# (STArray# Int
c Int
_ MutableArray# RealWorld e
_)) =
let go :: Int -> io Int
go Int
i = Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 Bool -> io Int -> io Int -> io Int
forall a. Bool -> a -> a -> a
? Int -> io Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
c (io Int -> io Int) -> io Int -> io Int
forall a b. (a -> b) -> a -> b
$ do e
e <- MIOArray# io e
es MIOArray# io e -> Int -> io e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i; e -> io Bool
p e
e io Bool -> io Int -> io Int -> io Int
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
?^ Int -> io Int
go (Int -> Int
forall a. Enum a => a -> a
pred Int
i) (io Int -> io Int) -> io Int -> io Int
forall a b. (a -> b) -> a -> b
$ Int -> io Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
in Int -> io Int
go (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1))
instance (MonadIO io) => MapM io (MIOArray# io e) Int e
where
newMap' :: e -> [(Int, e)] -> io (MIOArray# io e)
newMap' e
defvalue [(Int, e)]
ascs = (Int, Int) -> e -> [(Int, e)] -> io (MIOArray# io e)
forall (m :: * -> *) v i e.
IndexedM m v i e =>
(i, i) -> e -> [(i, e)] -> m v
fromAssocs' ([(Int, e)] -> (Int, Int)
forall a b. Ord a => [(a, b)] -> (a, a)
ascsBounds [(Int, e)]
ascs) e
defvalue [(Int, e)]
ascs
>! :: MIOArray# io e -> Int -> io e
(>!) = MIOArray# io e -> Int -> io e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
(!#>)
overwrite :: MIOArray# io e -> [(Int, e)] -> io (MIOArray# io e)
overwrite = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (MIOArray# io e
-> [(Int, e)] -> ST RealWorld (STArray# RealWorld e))
-> MIOArray# io e
-> [(Int, e)]
-> io (MIOArray# io e)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... STArray# RealWorld e
-> [(Int, e)] -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) map key e.
MapM m map key e =>
map -> [(key, e)] -> m map
overwrite (STArray# RealWorld e
-> [(Int, e)] -> ST RealWorld (STArray# RealWorld e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> [(Int, e)]
-> ST RealWorld (STArray# RealWorld e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
kfoldrM :: (Int -> e -> acc -> io acc) -> acc -> MIOArray# io e -> io acc
kfoldrM = (Int -> e -> acc -> io acc) -> acc -> MIOArray# io e -> io acc
forall (m :: * -> *) l e r.
LinearM m l e =>
(Int -> e -> r -> m r) -> r -> l -> m r
ofoldrM
kfoldlM :: (Int -> acc -> e -> io acc) -> acc -> MIOArray# io e -> io acc
kfoldlM = (Int -> acc -> e -> io acc) -> acc -> MIOArray# io e -> io acc
forall (m :: * -> *) l e r.
LinearM m l e =>
(Int -> r -> e -> m r) -> r -> l -> m r
ofoldlM
instance (MonadIO io) => IndexedM io (MIOArray# io e) Int e
where
fromAssocs :: (Int, Int) -> [(Int, e)] -> io (MIOArray# io e)
fromAssocs (Int, Int)
bnds = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> ([(Int, e)] -> ST RealWorld (STArray# RealWorld e))
-> [(Int, e)]
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, Int) -> [(Int, e)] -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) v i e.
IndexedM m v i e =>
(i, i) -> [(i, e)] -> m v
fromAssocs (Int, Int)
bnds
fromAssocs' :: (Int, Int) -> e -> [(Int, e)] -> io (MIOArray# io e)
fromAssocs' (Int, Int)
bnds = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (e -> [(Int, e)] -> ST RealWorld (STArray# RealWorld e))
-> e
-> [(Int, e)]
-> io (MIOArray# io e)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... (Int, Int)
-> e -> [(Int, e)] -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) v i e.
IndexedM m v i e =>
(i, i) -> e -> [(i, e)] -> m v
fromAssocs' (Int, Int)
bnds
writeM' :: MIOArray# io e -> Int -> e -> io ()
writeM' MIOArray# io e
es = ST RealWorld () -> io ()
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld () -> io ())
-> (Int -> e -> ST RealWorld ()) -> Int -> e -> io ()
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... STArray# RealWorld e -> Int -> e -> ST RealWorld ()
forall (m :: * -> *) v i e. IndexedM m v i e => v -> i -> e -> m ()
writeM' (MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack MIOArray# io e
es)
fromIndexed' :: v' -> io (MIOArray# io e)
fromIndexed' = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (v' -> ST RealWorld (STArray# RealWorld e))
-> v'
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v' -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) v i e v' j.
(IndexedM m v i e, Indexed v' j e) =>
v' -> m v
fromIndexed'
fromIndexedM :: v' -> io (MIOArray# io e)
fromIndexedM v'
es = do
Int
n <- v' -> io Int
forall (m :: * -> *) b i. BorderedM m b i => b -> m Int
getSizeOf v'
es
MIOArray# io e
copy <- Int -> e -> io (MIOArray# io e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
n (String -> e
forall a. String -> a
unreachEx String
"fromIndexedM")
[Int] -> (Int -> io ()) -> io ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> io ()) -> io ()) -> (Int -> io ()) -> io ()
forall a b. (a -> b) -> a -> b
$ \ Int
i -> v'
es v' -> Int -> io e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#> Int
i io e -> (e -> io ()) -> io ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MIOArray# io e -> Int -> e -> io ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM MIOArray# io e
copy Int
i
MIOArray# io e -> io (MIOArray# io e)
forall (m :: * -> *) a. Monad m => a -> m a
return MIOArray# io e
copy
instance (MonadIO io) => SortM io (MIOArray# io e) e
where
sortedMBy :: (e -> e -> Bool) -> MIOArray# io e -> io Bool
sortedMBy e -> e -> Bool
f = ST RealWorld Bool -> io Bool
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld Bool -> io Bool)
-> (MIOArray# io e -> ST RealWorld Bool)
-> MIOArray# io e
-> io Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> e -> Bool) -> STArray# RealWorld e -> ST RealWorld Bool
forall (m :: * -> *) s e.
SortM m s e =>
(e -> e -> Bool) -> s -> m Bool
sortedMBy e -> e -> Bool
f (STArray# RealWorld e -> ST RealWorld Bool)
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
sortMBy :: Compare e -> MIOArray# io e -> io ()
sortMBy = Compare e -> MIOArray# io e -> io ()
forall (m :: * -> *) v e i.
(LinearM m v e, BorderedM m v i) =>
Compare e -> v -> m ()
timSortBy
instance (MonadIO io) => Thaw io (SArray# e) (MIOArray# io e)
where
unsafeThaw :: SArray# e -> io (MIOArray# io e)
unsafeThaw = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (SArray# e -> ST RealWorld (STArray# RealWorld e))
-> SArray# e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
unsafeThaw
thaw :: SArray# e -> io (MIOArray# io e)
thaw = ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
forall (io :: * -> *) e.
MonadIO io =>
ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e)
pack (ST RealWorld (STArray# RealWorld e) -> io (MIOArray# io e))
-> (SArray# e -> ST RealWorld (STArray# RealWorld e))
-> SArray# e
-> io (MIOArray# io e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SArray# e -> ST RealWorld (STArray# RealWorld e)
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
thaw
instance (MonadIO io) => Freeze io (MIOArray# io e) (SArray# e)
where
unsafeFreeze :: MIOArray# io e -> io (SArray# e)
unsafeFreeze = ST RealWorld (SArray# e) -> io (SArray# e)
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld (SArray# e) -> io (SArray# e))
-> (MIOArray# io e -> ST RealWorld (SArray# e))
-> MIOArray# io e
-> io (SArray# e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> ST RealWorld (SArray# e)
forall (m :: * -> *) v' v. Freeze m v' v => v' -> m v
unsafeFreeze (STArray# RealWorld e -> ST RealWorld (SArray# e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld (SArray# e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
freeze :: MIOArray# io e -> io (SArray# e)
freeze = ST RealWorld (SArray# e) -> io (SArray# e)
forall (io :: * -> *) e. MonadIO io => ST RealWorld e -> io e
stToMIO (ST RealWorld (SArray# e) -> io (SArray# e))
-> (MIOArray# io e -> ST RealWorld (SArray# e))
-> MIOArray# io e
-> io (SArray# e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STArray# RealWorld e -> ST RealWorld (SArray# e)
forall (m :: * -> *) v' v. Freeze m v' v => v' -> m v
freeze (STArray# RealWorld e -> ST RealWorld (SArray# e))
-> (MIOArray# io e -> STArray# RealWorld e)
-> MIOArray# io e
-> ST RealWorld (SArray# e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MIOArray# io e -> STArray# RealWorld e
forall (io :: * -> *) e. MIOArray# io e -> STArray# RealWorld e
unpack
instance (Storable e) => Freeze IO (Int, Ptr e) (SArray# e)
where
freeze :: (Int, Ptr e) -> IO (SArray# e)
freeze (Int
n, Ptr e
ptr) = do
let !n' :: Int
n'@(I# Int#
n#) = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 Int
n
MIOArray# IO e
es' <- ST RealWorld (MIOArray# IO e) -> IO (MIOArray# IO e)
forall a. ST RealWorld a -> IO a
stToIO (ST RealWorld (MIOArray# IO e) -> IO (MIOArray# IO e))
-> (STRep RealWorld (MIOArray# IO e)
-> ST RealWorld (MIOArray# IO e))
-> STRep RealWorld (MIOArray# IO e)
-> IO (MIOArray# IO e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STRep RealWorld (MIOArray# IO e) -> ST RealWorld (MIOArray# IO e)
forall s a. STRep s a -> ST s a
ST (STRep RealWorld (MIOArray# IO e) -> IO (MIOArray# IO e))
-> STRep RealWorld (MIOArray# IO e) -> IO (MIOArray# IO e)
forall a b. (a -> b) -> a -> b
$ \ State# RealWorld
s1# -> case Int#
-> e
-> State# RealWorld
-> (# State# RealWorld, MutableArray# RealWorld e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# Int#
n# e
err State# RealWorld
s1# of
(# State# RealWorld
s2#, MutableArray# RealWorld e
marr# #) -> (# State# RealWorld
s2#, STArray# RealWorld e -> MIOArray# IO e
forall (io :: * -> *) e. STArray# RealWorld e -> MIOArray# io e
MIOArray# (Int -> Int -> MutableArray# RealWorld e -> STArray# RealWorld e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
n' Int
0 MutableArray# RealWorld e
marr#) #)
[Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. Int
n' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ Int
i -> Ptr e -> Int -> IO e
forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff Ptr e
ptr Int
i IO e -> (e -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MIOArray# IO e -> Int -> e -> IO ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM MIOArray# IO e
es' Int
i
MIOArray# IO e -> IO (SArray# e)
forall (m :: * -> *) v' v. Freeze m v' v => v' -> m v
freeze MIOArray# IO e
es'
where
err :: e
err = String -> e
forall a. String -> a
undEx String
"freeze {(Int, Ptr e) => SArray# e}" e -> Ptr e -> e
forall a (proxy :: * -> *). a -> proxy a -> a
`asProxyTypeOf` Ptr e
ptr
instance (Storable e) => Thaw IO (SArray# e) (Int, Ptr e)
where
thaw :: SArray# e -> IO (Int, Ptr e)
thaw (SArray# Int
n Int
o Array# e
arr#) = do
Ptr e
ptr <- Int -> IO (Ptr e)
forall a. Storable a => Int -> IO (Ptr a)
callocArray Int
n
[Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
o .. Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ i :: Int
i@(I# Int#
i#) -> let (# e
e #) = Array# e -> Int# -> (# e #)
forall a. Array# a -> Int# -> (# a #)
indexArray# Array# e
arr# Int#
i# in Ptr e -> Int -> e -> IO ()
forall a. Storable a => Ptr a -> Int -> a -> IO ()
pokeElemOff Ptr e
ptr Int
i e
e
(Int, Ptr e) -> IO (Int, Ptr e)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
n, Ptr e
ptr)
unpackSArray# :: SArray# e -> Array# e
unpackSArray# :: SArray# e -> Array# e
unpackSArray# = \ (SArray# Int
_ Int
_ Array# e
arr#) -> Array# e
arr#
offsetSArray# :: SArray# e -> Int#
offsetSArray# :: SArray# e -> Int#
offsetSArray# = \ (SArray# Int
_ (I# Int#
o#) Array# e
_) -> Int#
o#
packSArray# :: Int -> Array# e -> SArray# e
packSArray# :: Int -> Array# e -> SArray# e
packSArray# Int
n Array# e
arr# = Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 Int
n) Int
0 Array# e
arr#
fromSArray# :: SArray# e -> Array# e
fromSArray# :: SArray# e -> Array# e
fromSArray# (SArray# (I# Int#
c#) (I# Int#
o#) Array# e
arr#) = Array# e -> Int# -> Int# -> Array# e
forall a. Array# a -> Int# -> Int# -> Array# a
cloneArray# Array# e
arr# Int#
o# Int#
c#
coerceSArray# :: (Coercible a b) => SArray# a -> SArray# b
coerceSArray# :: SArray# a -> SArray# b
coerceSArray# = SArray# a -> SArray# b
coerce
unpackSTArray# :: STArray# s e -> MutableArray# s e
unpackSTArray# :: STArray# s e -> MutableArray# s e
unpackSTArray# = \ (STArray# Int
_ Int
_ MutableArray# s e
marr#) -> MutableArray# s e
marr#
offsetSTArray# :: STArray# s e -> Int#
offsetSTArray# :: STArray# s e -> Int#
offsetSTArray# = \ (STArray# Int
_ (I# Int#
o#) MutableArray# s e
_) -> Int#
o#
packSTArray# :: Int -> MutableArray# s e -> STArray# s e
packSTArray# :: Int -> MutableArray# s e -> STArray# s e
packSTArray# Int
n MutableArray# s e
marr# = Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 Int
n) Int
0 MutableArray# s e
marr#
fromSTArray# :: STArray# s e -> State# s -> (# State# s, MutableArray# s e #)
fromSTArray# :: STArray# s e -> State# s -> (# State# s, MutableArray# s e #)
fromSTArray# (STArray# (I# Int#
c#) (I# Int#
o#) MutableArray# s e
marr#) = MutableArray# s e
-> Int# -> Int# -> State# s -> (# State# s, MutableArray# s e #)
forall d a.
MutableArray# d a
-> Int# -> Int# -> State# d -> (# State# d, MutableArray# d a #)
cloneMutableArray# MutableArray# s e
marr# Int#
o# Int#
c#
coerceSTArray# :: (Coercible a b) => STArray# s a -> STArray# s b
coerceSTArray# :: STArray# s a -> STArray# s b
coerceSTArray# = STArray# s a -> STArray# s b
coerce
{-# INLINE done #-}
done :: STArray# s e -> ST s (SArray# e)
done :: STArray# s e -> ST s (SArray# e)
done (STArray# Int
n Int
o MutableArray# s e
marr#) = STRep s (SArray# e) -> ST s (SArray# e)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# e) -> ST s (SArray# e))
-> STRep s (SArray# e) -> ST s (SArray# e)
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# -> case MutableArray# s e -> State# s -> (# State# s, Array# e #)
forall d a.
MutableArray# d a -> State# d -> (# State# d, Array# a #)
unsafeFreezeArray# MutableArray# s e
marr# State# s
s1# of
(# State# s
s2#, Array# e
arr# #) -> (# State# s
s2#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# Int
n Int
o Array# e
arr# #)
{-# INLINE done' #-}
done' :: Int -> MutableArray# s e -> STRep s (STArray# s e)
done' :: Int -> MutableArray# s e -> STRep s (STArray# s e)
done' Int
n MutableArray# s e
marr# = \ State# s
s1# -> (# State# s
s1#, Int -> Int -> MutableArray# s e -> STArray# s e
forall s e. Int -> Int -> MutableArray# s e -> STArray# s e
STArray# Int
n Int
0 MutableArray# s e
marr# #)
{-# INLINE nubSorted #-}
nubSorted :: Compare e -> SArray# e -> SArray# e
nubSorted :: Compare e -> SArray# e -> SArray# e
nubSorted Compare e
_ SArray# e
Z = SArray# e
forall e. Nullable e => e
Z
nubSorted Compare e
f SArray# e
es = [e] -> SArray# e
forall l e. Linear l e => [e] -> l
fromList ([e] -> SArray# e) -> [e] -> SArray# e
forall a b. (a -> b) -> a -> b
$ (e -> [e] -> [e]) -> [e] -> [e] -> [e]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr e -> [e] -> [e]
fun [SArray# e -> e
forall l e. Linear l e => l -> e
last SArray# e
es] ((SArray# e
es SArray# e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^) (Int -> e) -> [Int] -> [e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int
0 .. SArray# e -> Int
forall b i. Bordered b i => b -> Int
sizeOf SArray# e
es Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2])
where
fun :: e -> [e] -> [e]
fun = \ e
e [e]
ls -> e
e Compare e
`f` [e] -> e
forall l e. Linear l e => l -> e
head [e]
ls Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ Bool -> [e] -> [e] -> [e]
forall a. Bool -> a -> a -> a
? [e]
ls ([e] -> [e]) -> [e] -> [e]
forall a b. (a -> b) -> a -> b
$ e
e e -> [e] -> [e]
forall a. a -> [a] -> [a]
: [e]
ls
before :: Int -> e -> SArray# e -> SArray# e
before :: Int -> e -> SArray# e -> SArray# e
before n :: Int
n@(I# Int#
n#) e
e es :: SArray# e
es@(SArray# c :: Int
c@(I# Int#
c#) (I# Int#
o#) Array# e
arr#)
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = SArray# e
es SArray# e -> e -> SArray# e
forall l e. Linear l e => l -> e -> l
:< e
e
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = e
e e -> SArray# e -> SArray# e
forall l e. Linear l e => e -> l -> l
:> SArray# e
es
| Bool
True = (forall s. ST s (SArray# e)) -> SArray# e
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (SArray# e)) -> SArray# e)
-> (forall s. ST s (SArray# e)) -> SArray# e
forall a b. (a -> b) -> a -> b
$ STRep s (SArray# e) -> ST s (SArray# e)
forall s a. STRep s a -> ST s a
ST (STRep s (SArray# e) -> ST s (SArray# e))
-> STRep s (SArray# e) -> ST s (SArray# e)
forall a b. (a -> b) -> a -> b
$ \ State# s
s1# -> case Int# -> e -> State# s -> (# State# s, MutableArray# s e #)
forall a d.
Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
newArray# (Int#
c# Int# -> Int# -> Int#
+# Int#
1#) e
e State# s
s1# of
(# State# s
s2#, MutableArray# s e
marr# #) -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
arr# Int#
o# MutableArray# s e
marr# Int#
0# Int#
n# State# s
s2# of
State# s
s3# -> case Array# e
-> Int#
-> MutableArray# s e
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
Array# a
-> Int#
-> MutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
copyArray# Array# e
arr# (Int#
o# Int# -> Int# -> Int#
+# Int#
n#) MutableArray# s e
marr# (Int#
n# Int# -> Int# -> Int#
+# Int#
1#) (Int#
c# Int# -> Int# -> Int#
-# Int#
n#) State# s
s3# of
State# s
s4# -> case MutableArray# s e -> State# s -> (# State# s, Array# e #)
forall d a.
MutableArray# d a -> State# d -> (# State# d, Array# a #)
unsafeFreezeArray# MutableArray# s e
marr# State# s
s4# of
(# State# s
s5#, Array# e
res# #) -> (# State# s
s5#, Int -> Int -> Array# e -> SArray# e
forall e. Int -> Int -> Array# e -> SArray# e
SArray# (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
0 Array# e
res# #)
ascsBounds :: (Ord a) => [(a, b)] -> (a, a)
ascsBounds :: [(a, b)] -> (a, a)
ascsBounds = \ ((a
x, b
_) : [(a, b)]
xs) -> ((a, b) -> (a, a) -> (a, a)) -> (a, a) -> [(a, b)] -> (a, a)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\ (a
e, b
_) (a
mn, a
mx) -> (a -> a -> a
forall a. Ord a => a -> a -> a
min a
mn a
e, a -> a -> a
forall a. Ord a => a -> a -> a
max a
mx a
e)) (a
x, a
x) [(a, b)]
xs
undEx :: String -> a
undEx :: String -> a
undEx = IndexException -> a
forall a e. Exception e => e -> a
throw (IndexException -> a) -> (String -> IndexException) -> String -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IndexException
UndefinedValue (String -> IndexException) -> ShowS -> String -> IndexException
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"in SDP.Prim.SArray."
overEx :: String -> a
overEx :: String -> a
overEx = IndexException -> a
forall a e. Exception e => e -> a
throw (IndexException -> a) -> (String -> IndexException) -> String -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IndexException
IndexOverflow (String -> IndexException) -> ShowS -> String -> IndexException
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"in SDP.Prim.SArray."
underEx :: String -> a
underEx :: String -> a
underEx = IndexException -> a
forall a e. Exception e => e -> a
throw (IndexException -> a) -> (String -> IndexException) -> String -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IndexException
IndexUnderflow (String -> IndexException) -> ShowS -> String -> IndexException
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"in SDP.Prim.SArray."
pfailEx :: String -> a
pfailEx :: String -> a
pfailEx = PatternMatchFail -> a
forall a e. Exception e => e -> a
throw (PatternMatchFail -> a)
-> (String -> PatternMatchFail) -> String -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> PatternMatchFail
PatternMatchFail (String -> PatternMatchFail) -> ShowS -> String -> PatternMatchFail
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"in SDP.Prim.SArray."
unreachEx :: String -> a
unreachEx :: String -> a
unreachEx = UnreachableException -> a
forall a e. Exception e => e -> a
throw (UnreachableException -> a)
-> (String -> UnreachableException) -> String -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> UnreachableException
UnreachableException (String -> UnreachableException)
-> ShowS -> String -> UnreachableException
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"in SDP.Prim.SArray."