packages feed

dynamic-mvector 0.1.0.4 → 0.1.0.5

raw patch · 2 files changed

+31/−31 lines, 2 filesdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

- Data.Vector.Mutable.Dynamic: instance Typeable MVector
- Data.Vector.Mutable.Dynamic: instance Typeable MVectorData

Files

Data/Vector/Mutable/Dynamic.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE DeriveDataTypeable #-} --- | A wrapper around MVector that enables pushing, popping and extending.     +-- | A wrapper around MVector that enables pushing, popping and extending.  module Data.Vector.Mutable.Dynamic(       MVector, STVector, IOVector,@@ -8,7 +8,7 @@       new, replicate, unsafeNew, unsafeReplicate,        -- * Accessing-      read, write, readFront, readBack, +      read, write, readFront, readBack,       unsafeRead, unsafeWrite, unsafeReadFront, unsafeReadBack, set,        -- * Conversion@@ -17,7 +17,7 @@       -- * Length information       length, null, capacity, -      -- * Copying +      -- * Copying       clone, copy, move, unsafeCopy, unsafeMove,        -- * Modification@@ -53,7 +53,7 @@ newReserve :: Int newReserve = 5 --- | Create an immutable copy of the vector. +-- | Create an immutable copy of the vector. freeze :: PrimMonad m => MVector (PrimState m) a -> m (V.Vector a) freeze (MVector v) = do     MVectorData s v <- readMutVar v@@ -101,7 +101,7 @@ {-# INLINABLE null #-}  -- | Create a new vector of given length. The elements are uninitialized and throw error upon accessing.--- The "Int" argument must be positive. +-- The "Int" argument must be positive. new :: PrimMonad m => Int -> m (MVector (PrimState m) a) new i = do     v  <- MV.new (i + newReserve)@@ -116,11 +116,11 @@ {-# INLINABLE unsafeNew #-}  -- | Returns a vector consisting of a value repeated the given times.--- Throws an error if the "Int" argument is negative.  +-- Throws an error if the "Int" argument is negative. replicate :: PrimMonad m => Int -> a -> m (MVector (PrimState m) a) replicate i a = do     v <- MV.new i-    MV.set v a  +    MV.set v a     liftM MVector $ newMutVar (MVectorData i v) {-# INLINABLE replicate #-} @@ -128,7 +128,7 @@ unsafeReplicate :: PrimMonad m => Int -> a -> m (MVector (PrimState m) a) unsafeReplicate i a = do     v <- MV.unsafeNew i-    MV.set v a  +    MV.set v a     liftM MVector $ newMutVar (MVectorData i v) {-# INLINABLE unsafeReplicate #-} @@ -138,7 +138,7 @@     MVectorData s v <- readMutVar v     if (i >= s || i < 0) then         error "Data.Vector.Mutable.Dynamic: read: index out of bounds"-    else +    else         MV.unsafeRead v i {-# INLINABLE read #-} @@ -153,7 +153,7 @@     MVectorData s v <- readMutVar v     if (i >= s || i < 0) then         error "Data.Vector.Mutable.Dynamic: write: index out of bounds"-    else +    else         MV.unsafeWrite v i a {-# INLINABLE write #-} @@ -171,7 +171,7 @@     writeMutVar var (MVectorData 0 v) {-# INLINABLE clear #-} --- | Set all the elements to a value. +-- | Set all the elements to a value. set :: PrimMonad m => MVector (PrimState m) a -> a -> m () set (MVector v) a = do     MVectorData s v <- readMutVar v@@ -186,7 +186,7 @@     MV.copy (_data v1) (_data v2) {-# INLINABLE copy #-} --- | Copy the contents of the right vector to the left one without checking length and overlapping. +-- | Copy the contents of the right vector to the left one without checking length and overlapping. unsafeCopy :: PrimMonad m => MVector (PrimState m) a -> MVector (PrimState m) a -> m () unsafeCopy (MVector v1) (MVector v2) = do     v1 <- readMutVar v1@@ -203,7 +203,7 @@ {-# INLINABLE move #-}  -- | Move the contents of the right vector to the left one. The vectors must have the same length and may overlap.--- Input lengths are unchecked.  +-- Input lengths are unchecked. unsafeMove :: PrimMonad m => MVector (PrimState m) a -> MVector (PrimState m) a -> m () unsafeMove (MVector v1) (MVector v2) = do     v1 <- readMutVar v1@@ -211,7 +211,7 @@     MV.unsafeMove (_data v1) (_data v2) {-# INLINABLE unsafeMove #-} --- | Create a copy from a mutable vector. +-- | Create a copy from a mutable vector. clone :: PrimMonad m => MVector (PrimState m) a -> m (MVector (PrimState m) a) clone (MVector v) = do     MVectorData s v <- readMutVar v@@ -235,7 +235,7 @@ {-# INLINABLE reserve #-}  -- | Ensure that an amount of capacity is reserved in the vector. A no-op if there is already enough capacity.--- The argument is unchecked. +-- The argument is unchecked. unsafeReserve :: PrimMonad m => MVector (PrimState m) a -> Int -> m () unsafeReserve (MVector v) i = do     MVectorData s v' <- readMutVar v@@ -246,7 +246,7 @@         writeMutVar v (MVectorData s v'') {-# INLINABLE unsafeReserve #-} --- | Set reserved capacity to 0. +-- | Set reserved capacity to 0. trim :: PrimMonad m => MVector (PrimState m) a -> m () trim v = unsafeReserve v 0 {-# INLINABLE trim #-}@@ -266,33 +266,33 @@ {-# INLINABLE pushBack #-}  --- | Read the back value and remove it from the vector. Throws an error if the vector is empty. -popBack :: PrimMonad m => MVector (PrimState m) a -> m a +-- | Read the back value and remove it from the vector. Throws an error if the vector is empty.+popBack :: PrimMonad m => MVector (PrimState m) a -> m a popBack (MVector v) = do     MVectorData s vec <- readMutVar v     if (s <= 0) then         error "Data.Vector.Mutable.Dynamic: popBack: empty vector"-    else do +    else do         a <- MV.unsafeRead vec (s - 1)         if (s < quot (MV.length vec) 2) then do             vec' <- MV.unsafeGrow vec (s - 1)             writeMutVar v (MVectorData (s - 1) vec')         else             writeMutVar v (MVectorData (s - 1) vec)-        return a +        return a {-# INLINABLE popBack #-}  -- | Read the back value and remove it from the vector, without checking.-unsafePopBack :: PrimMonad m => MVector (PrimState m) a -> m a +unsafePopBack :: PrimMonad m => MVector (PrimState m) a -> m a unsafePopBack (MVector v) = do     MVectorData s vec <- readMutVar v     a <- MV.unsafeRead vec (s - 1)-    if (s < quot (MV.length vec) 2) then do +    if (s < quot (MV.length vec) 2) then do         vec' <- MV.unsafeGrow vec (s - 1)         writeMutVar v (MVectorData (s - 1) vec')     else-        writeMutVar v (MVectorData (s - 1) vec)        -    return a +        writeMutVar v (MVectorData (s - 1) vec)+    return a {-# INLINABLE unsafePopBack #-}  -- | Read the back value.  Throws an error if the vector is empty.@@ -322,7 +322,7 @@         MV.unsafeRead v 0 {-# INLINABLE readFront #-} --- | Read the front value without checking. +-- | Read the front value without checking. unsafeReadFront :: PrimMonad m => MVector (PrimState m) a -> m a unsafeReadFront (MVector v) = do     MVectorData s v <- readMutVar v@@ -338,10 +338,10 @@     if (sa + sb > MV.length va) then do         va' <- MV.unsafeGrow va (sa + sb)         MV.unsafeCopy (MV.unsafeSlice sa sb va') (MV.unsafeSlice 0 sb vb)-        writeMutVar a (MVectorData (sa + sb) va') +        writeMutVar a (MVectorData (sa + sb) va')     else do         MV.unsafeCopy (MV.unsafeSlice sa sb va) (MV.unsafeSlice 0 sb vb)-        writeMutVar a (MVectorData (sa + sb) va) +        writeMutVar a (MVectorData (sa + sb) va) {-# INLINABLE extend #-}  -- | Apply a function to an immutable copy of the vector.@@ -349,8 +349,8 @@ frozen v f = liftM f (freeze v) {-# INLINABLE frozen #-} --- | Apply a function to the vector recast as immutable. --- This is usually unsafe if we later modify the vector. +-- | Apply a function to the vector recast as immutable.+-- This is usually unsafe if we later modify the vector. unsafeFrozen :: PrimMonad m => MVector (PrimState m) a -> (V.Vector a -> b) -> m b unsafeFrozen v f = liftM f (unsafeFreeze v) {-# INLINABLE unsafeFrozen #-}
dynamic-mvector.cabal view
@@ -1,6 +1,6 @@  name:                dynamic-mvector-version:             0.1.0.4+version:             0.1.0.5 synopsis:            A wrapper around MVector that enables pushing, popping and extending.      homepage:            https://github.com/AndrasKovacs/dynamic-mvector license:             BSD3@@ -13,5 +13,5 @@  library   exposed-modules:     Data.Vector.Mutable.Dynamic-  build-depends:       base >=4.7 && <4.9, primitive >=0.5 && <0.7, vector >=0.10+  build-depends:       base >=4.7 && <5, primitive >=0.5 && <0.7, vector >=0.10   default-language:    Haskell2010