module Data.Vector (
Vector(..), module Data.Vector.IVector
) where
import Data.Vector.IVector
import qualified Data.Vector.Mutable as Mut
import Control.Monad.ST ( runST )
import GHC.ST ( ST(..) )
import GHC.Prim ( Array#, unsafeFreezeArray#, indexArray#, (+#) )
import GHC.Base ( Int(..) )
data Vector a = Vector !Int
!Int
(Array# a)
instance IVector Vector a where
vnew init = runST (do
Mut.Vector i n marr# <- init
ST (\s# -> case unsafeFreezeArray# marr# s# of
(# s2#, arr# #) -> (# s2#, Vector i n arr# #)))
vlength (Vector _ n _) = n
unsafeSlice (Vector i _ arr#) j n = Vector (i+j) n arr#
unsafeIndex (Vector (I# i#) _ arr#) (I# j#) f
= case indexArray# arr# (i# +# j#) of (# x #) -> f x
instance Eq a => Eq (Vector a) where
(==) = eq
instance Ord a => Ord (Vector a) where
compare = cmp