module Data.Vector.Storable.Mutable( MVector(..) )
where
import qualified Data.Vector.Generic.Mutable as G
import Foreign.Storable
import Foreign.ForeignPtr
data MVector a = MVector !Int
!Int
!(ForeignPtr a)
instance G.MVectorPure MVector a where
length (MVector _ n _) = n
unsafeSlice (MVector i _ p) j m = MVector (i+j) m p
overlaps (MVector i m p) (MVector j n q)
= True
instance Storable a => G.MVector MVector IO a where
unsafeNew n = MVector 0 n `fmap` mallocForeignPtrArray n
unsafeRead (MVector i n p) j = withForeignPtr p $ \ptr ->
peekElemOff ptr (i+j)
unsafeWrite (MVector i n p) j x = withForeignPtr p $ \ptr ->
pokeElemOff ptr (i+j) x
clear _ = return ()