Remove unneeded code
[darcs-mirrors/vector.git] / Data / Vector.hs
1 {-# LANGUAGE MagicHash, UnboxedTuples, FlexibleInstances, MultiParamTypeClasses #-}
2
3 -- |
4 -- Module : Data.Vector
5 -- Copyright : (c) Roman Leshchinskiy 2008
6 -- License : BSD-style
7 --
8 -- Maintainer : rl@cse.unsw.edu.au
9 -- Stability : experimental
10 -- Portability : non-portable
11 --
12 -- Boxed vectors
13 --
14
15 module Data.Vector (
16 Vector(..), module Data.Vector.IVector
17 ) where
18
19 import Data.Vector.IVector
20 import qualified Data.Vector.Mutable as Mut
21
22 import Control.Monad.ST ( runST )
23
24 import GHC.ST ( ST(..) )
25 import GHC.Prim ( Array#, unsafeFreezeArray#, indexArray#, (+#) )
26 import GHC.Base ( Int(..) )
27
28 data Vector a = Vector {-# UNPACK #-} !Int
29 {-# UNPACK #-} !Int
30 (Array# a)
31
32 instance IVector Vector a where
33 {-# INLINE new #-}
34 new init = runST (do
35 Mut.Vector i n marr# <- init
36 ST (\s# -> case unsafeFreezeArray# marr# s# of
37 (# s2#, arr# #) -> (# s2#, Vector i n arr# #)
38 ))
39
40 {-# INLINE vlength #-}
41 vlength (Vector _ n _) = n
42
43 {-# INLINE unsafeSlice #-}
44 unsafeSlice (Vector i _ arr#) j n = Vector (i+j) n arr#
45
46 {-# INLINE unsafeIndex #-}
47 unsafeIndex (Vector (I# i#) _ arr#) (I# j#) f
48 = case indexArray# arr# (i# +# j#) of (# x #) -> f x
49