storablevector 0.2.7 → 0.2.7.1
raw patch · 3 files changed
+23/−7 lines, 3 filesdep ~syb
Dependency ranges changed: syb
Files
- Data/StorableVector.hs +9/−2
- Data/StorableVector/Cursor.hs +11/−2
- storablevector.cabal +3/−3
Data/StorableVector.hs view
@@ -785,7 +785,14 @@ fst $ unfoldrN n (const $ Just (c, ())) () -} --- fast implementation+{-+fast implementation++Maybe it could be made even faster by plainly copying the bit pattern of the first element.+Since there is no function like 'memset',+we could not warrant that the implementation is really efficient+for the actual machine we run on.+-} replicate :: (Storable a) => Int -> a -> Vector a replicate n c = if n <= 0@@ -980,7 +987,7 @@ {-# INLINE take #-} -- | /O(1)/ 'drop' @n xs@ returns the suffix of @xs@ after the first @n@--- elements, or @[]@ if @n > 'length' xs@.+-- elements, or 'empty' if @n > 'length' xs@. drop :: (Storable a) => Int -> Vector a -> Vector a drop n ps@(SV x s l) | n <= 0 = ps
Data/StorableVector/Cursor.hs view
@@ -31,7 +31,7 @@ I hope that this is more efficient. With this restriction @s@ cannot be e.g. a function type but this would kill performance anyway.-Functions which need this flexibility may fall back to other data structures+Functions that need this flexibility may fall back to other data structures (lists or chunky StorableVectors) and convert to the Cursor structure later. -} -- | Cf. StreamFusion Data.Stream@@ -50,7 +50,7 @@ Buffer { memory :: {-# UNPACK #-} !(ForeignPtr a), size :: {-# UNPACK #-} !Int, -- size of allocated memory, I think I only need it for debugging- gen :: {-# UNPACK #-} !(Generator a),+ gen :: {-# UNPACK #-} !(Generator a), -- we need this indirection for the existential type in Generator cursor :: {-# UNPACK #-} !(IORef Int) } @@ -156,6 +156,9 @@ {-# INLINE cons #-} {- | This is expensive and should not be used to construct lists iteratively!+A recursion-enabling 'cons' would be 'consN'+that allocates a buffer of given size,+initializes the leading cell and sets the buffer pointer to the next cell. -} cons :: Storable a => a -> Vector a -> Vector a@@ -221,6 +224,12 @@ withForeignPtr p (\q -> pokeElemOff q c a) >> return (Just a) +{-+It is tempting to turn this into a simple loop without the IORefs.+This could be compiled to an efficient strict loop,+but it would fail if the vector content depends on its own,+like in @fix (consN 1000 'a')@.+-} -- | evaluate all values up to a given position evaluateToIO :: Storable a => Int -> Buffer a -> IO ()
storablevector.cabal view
@@ -1,5 +1,5 @@ Name: storablevector-Version: 0.2.7+Version: 0.2.7.1 Category: Data Synopsis: Fast, packed, strict storable arrays with a list interface like ByteString Description:@@ -51,7 +51,7 @@ Source-Repository this type: darcs location: http://code.haskell.org/storablevector/- tag: 0.2.7+ tag: 0.2.7.1 Library Build-Depends:@@ -71,7 +71,7 @@ If flag(separateSYB) Build-Depends: base >=4 && <5,- syb >=0.1 && <0.2+ syb >=0.1 && <0.4 Else Build-Depends: base >=3 && <4