packages feed

pipes-vector (empty) → 0.3.0.0

raw patch · 4 files changed

+100/−0 lines, 4 filesdep +basedep +pipesdep +primitivesetup-changed

Dependencies added: base, pipes, primitive, transformers, vector

Files

+ Control/Proxy/Vector.hs view
@@ -0,0 +1,47 @@+module Control.Proxy.Vector ( toVectorD, runToVectorK, runToVectorP ) where++import           Control.Applicative+import           Control.Monad+import           Control.Monad.Primitive+import           Control.Proxy+import           Control.Proxy.Trans.State as S+import qualified Data.Vector.Unboxed.Mutable as MVU+import qualified Data.Vector.Generic as V+import qualified Data.Vector.Generic.Mutable as M+import qualified Data.Vector.Unboxed as VU++data ToVectorState v m e = ToVecS { result :: v (PrimState m) e+                                  , idx    :: Int+                                  }++maxChunkSize = 8*1024*1024++toVectorD+    :: (PrimMonad m, Proxy p, M.MVector v e)+    => () -> Consumer (S.StateP (ToVectorState v m e) p) e m r+toVectorD () = forever $ do+     length <- M.length . result <$> get+     pos <- idx `liftM` get+     when (pos >= length) $ do+         v <- result `liftM` get+         v' <- lift $ M.unsafeGrow v (min length maxChunkSize)+         modify $ \(ToVecS r i) -> ToVecS v' i+     r <- request ()+     v <- result `liftM` get+     lift $ M.unsafeWrite v pos r+     modify $ \(ToVecS r i) -> ToVecS r (pos+1)++runToVectorK+    :: (PrimMonad m, MVU.Unbox e, Monad (p a' a b' b m), Proxy p, MonadTrans (p a' a b' b))+    => (q -> StateP (ToVectorState VU.MVector m e) p a' a b' b m r)+    -> (q -> p a' a b' b m (VU.Vector e))+runToVectorK k q = runToVectorP (k q)++runToVectorP+    :: (PrimMonad m, MVU.Unbox e, Monad (p a' a b' b m), Proxy p, MonadTrans (p a' a b' b))+    => StateP (ToVectorState VU.MVector m e) p a' a b' b m r -> p a' a b' b m (VU.Vector e)+runToVectorP x = do+    v <- lift $ MVU.new 10+    s <- execStateP (ToVecS v 0) x+    frozen <- lift $ V.freeze (result s)+    return $ VU.take (idx s) frozen
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Ben Gamari++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Ben Gamari nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pipes-vector.cabal view
@@ -0,0 +1,21 @@+name:                pipes-vector+version:             0.3.0.0+synopsis:            Various proxies for streaming data into and out of vectors+description:         Proxies for streaming data into and out of vectors.        +license:             BSD3+license-file:        LICENSE+author:              Ben Gamari+maintainer:          bgamari.foss@gmail.com+-- copyright:           +category:            Control+build-type:          Simple+cabal-version:       >=1.10++library+  exposed-modules:     Control.Proxy.Vector+  build-depends:       base >=3.0 && <5,+                       transformers >= 0.3 && < 1.0,+                       primitive >=0.4 && <1.0,+                       pipes >=3.3 && <3.4,+                       vector >=0.9 && <1.0+  default-language:    Haskell2010