module Data.RangeMin.Common.Vector (inlineCreate, write, read, new, newWith, drop, slice, sliceM, unsafeFreeze, minIndex,
(!), getRow, G.Vector, GM.MVector, G.Mutable) where
import Control.Monad.Primitive
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Generic.Mutable as GM
import Data.RangeMin.Common.ST
import qualified Data.Vector.Generic.New as New
import Prelude hiding (read, drop)
unsafeFreeze :: (PrimMonad m, G.Vector v a) => G.Mutable v (PrimState m) a -> m (v a)
unsafeFreeze = G.unsafeFreeze
sliceM :: GM.MVector v a => Int -> Int -> v s a -> v s a
sliceM = GM.unsafeSlice
write :: (PrimMonad m, GM.MVector v a) => v (PrimState m) a -> Int -> a -> m ()
write = GM.unsafeWrite
read :: (PrimMonad m, GM.MVector v a) => v (PrimState m) a -> Int -> m a
read = GM.unsafeRead
new :: (PrimMonad m, GM.MVector v a) => Int -> m (v (PrimState m) a)
new = GM.unsafeNew
newWith :: (PrimMonad m, GM.MVector v a) => Int -> a -> m (v (PrimState m) a)
newWith = GM.unsafeNewWith
drop :: G.Vector v a => Int -> v a -> v a
drop = G.unsafeDrop
slice :: G.Vector v a => Int -> Int -> v a -> v a
slice = G.unsafeSlice
minIndex :: (G.Vector v a, Ord a) => v a -> Int -> Int -> Int
minIndex !xs !i !j
| xs ! i <= xs ! j = i
| otherwise = j
(!) :: G.Vector v a => v a -> Int -> a
(!) = G.unsafeIndex
getRow :: G.Vector v a => Int -> v a -> Int -> Int -> a
getRow !cols !vec !i = (!) row
where !row = drop (i * cols) vec
inlineCreate :: G.Vector v a => (forall s . ST s (G.Mutable v s a)) -> v a
inlineCreate m = inlineNew (New.New m)
inlineNew :: G.Vector v a => New.New v a -> v a
inlineNew !m = inlineRunST (unsafeFreeze =<< New.run m)