module Data.Vector.Unboxed (
Vector(..), module Data.Vector.IVector
) where
import Data.Vector.IVector
import qualified Data.Vector.Unboxed.Mutable as Mut
import Data.Vector.Unboxed.Unbox
import Control.Monad.ST ( runST )
import GHC.ST ( ST(..) )
import GHC.Prim ( ByteArray#, unsafeFreezeByteArray#, (+#) )
import GHC.Base ( Int(..) )
data Vector a = Vector !Int
!Int
ByteArray#
instance Unbox a => IVector Vector a where
vnew init = runST (do
Mut.Vector i n marr# <- init
ST (\s# -> case unsafeFreezeByteArray# 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 = f (at# arr# (i# +# j#))
instance (Unbox a, Eq a) => Eq (Vector a) where
(==) = eq
instance (Unbox a, Ord a) => Ord (Vector a) where
compare = cmp