-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Fast, packed, strict storable arrays with a list interface like ByteString -- -- Fast, packed, strict storable arrays with a list interface, a chunky -- lazy list interface with variable chunk size and an interface for -- write access via the ST monad. This is much like -- bytestring and binary but can be used for every -- Foreign.Storable.Storable type. See also packages -- http://hackage.haskell.org/cgi-bin/hackage-scripts/package/vector, -- http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uvector -- with a similar intention. -- -- We do not provide advanced fusion optimization, since especially for -- lazy vectors this would either be incorrect or not applicable. For -- fusion see storablevector-streamfusion package. @package storablevector @version 0.2.4 -- | A module containing semi-public StorableVector internals. This exposes -- the StorableVector representation and low level construction -- functions. Modules which extend the StorableVector system will need to -- use this module while ideally most users will be able to make do with -- the public interface modules. module Data.StorableVector.Base -- | A space-efficient representation of a vector, supporting many -- efficient operations. -- -- Instances of Eq, Ord, Read, Show, Data, Typeable data Vector a SV :: !!ForeignPtr a -> !!Int -> !!Int -> Vector a -- | A variety of head for non-empty Vectors. unsafeHead -- omits the check for the empty case, so there is an obligation on the -- programmer to provide a proof that the Vector is non-empty. unsafeHead :: (Storable a) => Vector a -> a -- | A variety of tail for non-empty Vectors. unsafeTail -- omits the check for the empty case. As with unsafeHead, the -- programmer must provide a separate proof that the Vector is non-empty. unsafeTail :: (Storable a) => Vector a -> Vector a -- | A variety of last for non-empty Vectors. unsafeLast -- omits the check for the empty case, so there is an obligation on the -- programmer to provide a proof that the Vector is non-empty. unsafeLast :: (Storable a) => Vector a -> a -- | A variety of init for non-empty Vectors. unsafeInit -- omits the check for the empty case. As with unsafeLast, the -- programmer must provide a separate proof that the Vector is non-empty. unsafeInit :: (Storable a) => Vector a -> Vector a -- | Unsafe Vector index (subscript) operator, starting from 0, -- returning a single element. This omits the bounds check, which means -- there is an accompanying obligation on the programmer to ensure the -- bounds are checked in some other way. unsafeIndex :: (Storable a) => Vector a -> Int -> a -- | A variety of take which omits the checks on n so there -- is an obligation on the programmer to provide a proof that 0 <= -- n <= length xs. unsafeTake :: (Storable a) => Int -> Vector a -> Vector a -- | A variety of drop which omits the checks on n so there -- is an obligation on the programmer to provide a proof that 0 <= -- n <= length xs. unsafeDrop :: (Storable a) => Int -> Vector a -> Vector a -- | Wrapper of mallocForeignPtrArray. create :: (Storable a) => Int -> (Ptr a -> IO ()) -> IO (Vector a) -- | Given the maximum size needed and a function to make the contents of a -- Vector, createAndTrim makes the Vector. The generating function -- is required to return the actual final size (<= the maximum size), -- and the resulting byte array is realloced to this size. -- -- createAndTrim is the main mechanism for creating custom, efficient -- Vector functions, using Haskell or C functions to fill the space. createAndTrim :: (Storable a) => Int -> (Ptr a -> IO Int) -> IO (Vector a) createAndTrim' :: (Storable a) => Int -> (Ptr a -> IO (Int, Int, b)) -> IO (Vector a, b) -- | A way of creating Vectors outside the IO monad. The Int -- argument gives the final size of the Vector. Unlike -- createAndTrim the Vector is not reallocated if the final size -- is less than the estimated size. unsafeCreate :: (Storable a) => Int -> (Ptr a -> IO ()) -> Vector a -- | O(1) Build a Vector from a ForeignPtr fromForeignPtr :: ForeignPtr a -> Int -> Vector a -- | O(1) Deconstruct a ForeignPtr from a Vector toForeignPtr :: Vector a -> (ForeignPtr a, Int, Int) -- | Run an action that is initialized with a pointer to the first element -- to be used. withStartPtr :: (Storable a) => Vector a -> (Ptr a -> Int -> IO b) -> IO b -- | Just like unsafePerformIO, but we inline it. Big performance gains as -- it exposes lots of things to further inlining. Very unsafe. In -- particular, you should do no memory allocation inside an -- inlinePerformIO block. On Hugs this is just -- unsafePerformIO. inlinePerformIO :: IO a -> a instance Typeable1 Vector instance (Data a) => Data (Vector a) -- | A time and space-efficient implementation of vectors using packed -- arrays, suitable for high performance use, both in terms of large data -- quantities, or high speed requirements. Vectors are encoded as strict -- arrays, held in a ForeignPtr, and can be passed between C and -- Haskell with little effort. -- -- This module is intended to be imported qualified, to avoid -- name clashes with Prelude functions. eg. -- --
--   import qualified Data.StorableVector as V
--   
-- -- Original GHC implementation by Bryan O'Sullivan. Rewritten to use -- UArray by Simon Marlow. Rewritten to support slices and use ForeignPtr -- by David Roundy. Polished and extended by Don Stewart. Generalized to -- any Storable value by Spencer Janssen. Chunky lazy stream, also with -- chunk pattern control, mutable access in ST monad, Builder monoid by -- Henning Thieleman. module Data.StorableVector -- | A space-efficient representation of a vector, supporting many -- efficient operations. -- -- Instances of Eq, Ord, Read, Show, Data, Typeable data Vector a -- | O(1) The empty Vector empty :: (Storable a) => Vector a -- | O(1) Construct a Vector containing a single element singleton :: (Storable a) => a -> Vector a -- | O(n) Convert a '[a]' into a 'Vector a'. pack :: (Storable a) => [a] -> Vector a -- | O(n) Converts a 'Vector a' to a '[a]'. unpack :: (Storable a) => Vector a -> [a] -- | O(n) Convert first n elements of a '[a]' into a -- 'Vector a'. packN :: (Storable a) => Int -> [a] -> (Vector a, [a]) -- | O(n) Convert a list into a Vector using a conversion -- function packWith :: (Storable b) => (a -> b) -> [a] -> Vector b -- | O(n) Convert a Vector into a list using a conversion -- function unpackWith :: (Storable a) => (a -> b) -> Vector a -> [b] -- | O(n) cons is analogous to (:) for lists, but of -- different complexity, as it requires a memcpy. cons :: (Storable a) => a -> Vector a -> Vector a -- | O(n) Append an element to the end of a Vector snoc :: (Storable a) => Vector a -> a -> Vector a -- | O(n) Append two Vectors append :: (Storable a) => Vector a -> Vector a -> Vector a -- | O(1) Extract the first element of a Vector, which must -- be non-empty. An exception will be thrown in the case of an empty -- Vector. head :: (Storable a) => Vector a -> a -- | O(1) Extract the last element of a Vector, which must be -- finite and non-empty. An exception will be thrown in the case of an -- empty Vector. last :: (Storable a) => Vector a -> a -- | O(1) Extract the elements after the head of a Vector, -- which must be non-empty. An exception will be thrown in the case of an -- empty Vector. tail :: (Storable a) => Vector a -> Vector a -- | O(1) Return all the elements of a Vector except the last -- one. An exception will be thrown in the case of an empty -- Vector. init :: Vector a -> Vector a -- | O(1) Test whether a Vector is empty. null :: Vector a -> Bool -- | O(1) length returns the length of a Vector as an -- Int. length :: Vector a -> Int viewL :: (Storable a) => Vector a -> Maybe (a, Vector a) viewR :: (Storable a) => Vector a -> Maybe (Vector a, a) switchL :: (Storable a) => b -> (a -> Vector a -> b) -> Vector a -> b switchR :: (Storable a) => b -> (Vector a -> a -> b) -> Vector a -> b -- | O(n) map f xs is the Vector obtained by -- applying f to each element of xs. map :: (Storable a, Storable b) => (a -> b) -> Vector a -> Vector b -- | O(n) reverse xs efficiently returns the -- elements of xs in reverse order. reverse :: (Storable a) => Vector a -> Vector a -- | O(n) The intersperse function takes a element and a -- Vector and `intersperses' that element between the elements of -- the Vector. It is analogous to the intersperse function on -- Lists. intersperse :: (Storable a) => a -> Vector a -> Vector a -- | The transpose function transposes the rows and columns of its -- Vector argument. transpose :: (Storable a) => [Vector a] -> [Vector a] -- | foldl, applied to a binary operator, a starting value -- (typically the left-identity of the operator), and a Vector, reduces -- the Vector using the binary operator, from left to right. This -- function is subject to array fusion. foldl :: (Storable a) => (b -> a -> b) -> b -> Vector a -> b -- | 'foldl\'' is like foldl, but strict in the accumulator. foldl' :: (Storable a) => (b -> a -> b) -> b -> Vector a -> b -- | foldl1 is a variant of foldl that has no starting value -- argument, and thus must be applied to non-empty Vectors. This -- function is subject to array fusion. An exception will be thrown in -- the case of an empty Vector. foldl1 :: (Storable a) => (a -> a -> a) -> Vector a -> a -- | 'foldl1\'' is like foldl1, but strict in the accumulator. An -- exception will be thrown in the case of an empty Vector. foldl1' :: (Storable a) => (a -> a -> a) -> Vector a -> a -- | foldr, applied to a binary operator, a starting value -- (typically the right-identity of the operator), and a Vector, -- reduces the Vector using the binary operator, from right to -- left. foldr :: (Storable a) => (a -> b -> b) -> b -> Vector a -> b -- | foldr1 is a variant of foldr that has no starting value -- argument, and thus must be applied to non-empty Vectors An -- exception will be thrown in the case of an empty Vector. foldr1 :: (Storable a) => (a -> a -> a) -> Vector a -> a -- | O(n) Concatenate a list of Vectors. concat :: (Storable a) => [Vector a] -> Vector a -- | Map a function over a Vector and concatenate the results concatMap :: (Storable a, Storable b) => (a -> Vector b) -> Vector a -> Vector b -- | O(n) Applied to a predicate and a Vector, any -- determines if any element of the Vector satisfies the -- predicate. any :: (Storable a) => (a -> Bool) -> Vector a -> Bool -- | O(n) Applied to a predicate and a Vector, all -- determines if all elements of the Vector satisfy the predicate. all :: (Storable a) => (a -> Bool) -> Vector a -> Bool -- | O(n) maximum returns the maximum value from a -- Vector This function will fuse. An exception will be thrown in -- the case of an empty Vector. maximum :: (Storable a, Ord a) => Vector a -> a -- | O(n) minimum returns the minimum value from a -- Vector This function will fuse. An exception will be thrown in -- the case of an empty Vector. minimum :: (Storable a, Ord a) => Vector a -> a -- | scanl is similar to foldl, but returns a list of -- successive reduced values from the left. This function will fuse. -- --
--   scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]
--   
-- -- Note that -- --
--   last (scanl f z xs) == foldl f z xs.
--   
scanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | scanl1 is a variant of scanl that has no starting value -- argument. This function will fuse. -- --
--   scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]
--   
scanl1 :: (Storable a) => (a -> a -> a) -> Vector a -> Vector a -- | scanr is the right-to-left dual of scanl. scanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | scanr1 is a variant of scanr that has no starting value -- argument. scanr1 :: (Storable a) => (a -> a -> a) -> Vector a -> Vector a -- | The mapAccumL function behaves like a combination of map -- and foldl; it applies a function to each element of a -- Vector, passing an accumulating parameter from left to right, -- and returning a final value of this accumulator together with the new -- list. mapAccumL :: (Storable a, Storable b) => (acc -> a -> (acc, b)) -> acc -> Vector a -> (acc, Vector b) -- | The mapAccumR function behaves like a combination of map -- and foldr; it applies a function to each element of a -- Vector, passing an accumulating parameter from right to left, -- and returning a final value of this accumulator together with the new -- Vector. mapAccumR :: (Storable a, Storable b) => (acc -> a -> (acc, b)) -> acc -> Vector a -> (acc, Vector b) -- | O(n) map functions, provided with the index at each position mapIndexed :: (Storable a, Storable b) => (Int -> a -> b) -> Vector a -> Vector b -- | O(n) replicate n x is a Vector of length -- n with x the value of every element. replicate :: (Storable a) => Int -> a -> Vector a -- | O(n), where n is the length of the result. The -- unfoldr function is analogous to the List 'unfoldr'. -- unfoldr builds a Vector from a seed value. The function -- takes the element and returns Nothing if it is done producing -- the 'Vector or returns Just (a,b), in which case, -- a is the next element in the Vector, and b is -- the seed value for further production. -- -- Examples: -- --
--      unfoldr (\x -> if x <= 5 then Just (x, x + 1) else Nothing) 0
--   == pack [0, 1, 2, 3, 4, 5]
--   
unfoldr :: (Storable b) => (a -> Maybe (b, a)) -> a -> Vector b -- | O(n) Like unfoldr, unfoldrN builds a -- Vector from a seed value. However, the length of the result is -- limited by the first argument to unfoldrN. This function is -- more efficient than unfoldr when the maximum length of the -- result is known. -- -- The following equation relates unfoldrN and unfoldr: -- --
--   fst (unfoldrN n f s) == take n (unfoldr f s)
--   
unfoldrN :: (Storable b) => Int -> (a -> Maybe (b, a)) -> a -> (Vector b, Maybe a) -- | O(n), where n is the length of the result. This function -- constructs a vector by evaluating a function that depends on the -- element index. It is a special case of unfoldrN and can in -- principle be parallelized. -- -- Examples: -- --
--      sample 26 (\x -> chr(ord 'a'+x))
--   == pack "abcdefghijklmnopqrstuvwxyz"
--   
sample :: (Storable a) => Int -> (Int -> a) -> Vector a -- | O(1) take n, applied to a Vector -- xs, returns the prefix of xs of length n, -- or xs itself if n > length xs. take :: (Storable a) => Int -> Vector a -> Vector a -- | O(1) drop n xs returns the suffix of -- xs after the first n elements, or [] if -- n > length xs. drop :: (Storable a) => Int -> Vector a -> Vector a -- | O(1) splitAt n xs is equivalent to -- (take n xs, drop n xs). splitAt :: (Storable a) => Int -> Vector a -> (Vector a, Vector a) -- | takeWhile, applied to a predicate p and a -- Vector xs, returns the longest prefix (possibly empty) -- of xs of elements that satisfy p. takeWhile :: (Storable a) => (a -> Bool) -> Vector a -> Vector a -- | dropWhile p xs returns the suffix remaining after -- takeWhile p xs. dropWhile :: (Storable a) => (a -> Bool) -> Vector a -> Vector a -- | span p xs breaks the Vector into two segments. -- It is equivalent to (takeWhile p xs, dropWhile p -- xs) span :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | spanEnd behaves like span but from the end of the -- Vector. We have -- --
--   spanEnd (not.isSpace) "x y z" == ("x y ","z")
--   
-- -- and -- --
--   spanEnd (not . isSpace) ps
--      ==
--   let (x,y) = span (not.isSpace) (reverse ps) in (reverse y, reverse x)
--   
spanEnd :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | break p is equivalent to span (not . -- p). break :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | breakEnd behaves like break but from the end of the -- Vector -- -- breakEnd p == spanEnd (not.p) breakEnd :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | The group function takes a Vector and returns a list of -- Vectors such that the concatenation of the result is equal to -- the argument. Moreover, each sublist in the result contains only equal -- elements. For example, -- --
--   group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"]
--   
-- -- It is a special case of groupBy, which allows the programmer to -- supply their own equality test. It is about 40% faster than groupBy -- (==) group :: (Storable a, Eq a) => Vector a -> [Vector a] -- | The groupBy function is the non-overloaded version of -- group. groupBy :: (Storable a) => (a -> a -> Bool) -> Vector a -> [Vector a] -- | O(n) Return all initial segments of the given Vector, -- shortest first. inits :: (Storable a) => Vector a -> [Vector a] -- | O(n) Return all final segments of the given Vector, -- longest first. tails :: (Storable a) => Vector a -> [Vector a] -- | O(n) Break a Vector into pieces separated by the -- argument, consuming the delimiter. I.e. -- --
--   split '\n' "a\nb\nd\ne" == ["a","b","d","e"]
--   split 'a'  "aXaXaXa"    == ["","X","X","X"]
--   split 'x'  "x"          == ["",""]
--   
-- -- and -- --
--   join [c] . split c == id
--   split == splitWith . (==)
--   
-- -- As for all splitting functions in this library, this function does not -- copy the substrings, it just constructs new Vectors that are -- slices of the original. split :: (Storable a, Eq a) => a -> Vector a -> [Vector a] -- | O(n) Splits a Vector into components delimited by -- separators, where the predicate returns True for a separator element. -- The resulting components do not contain the separators. Two adjacent -- separators result in an empty component in the output. eg. -- --
--   splitWith (=='a') "aabbaca" == ["","","bb","c",""]
--   splitWith (=='a') []        == []
--   
splitWith :: (Storable a) => (a -> Bool) -> Vector a -> [Vector a] -- | Like splitWith, except that sequences of adjacent separators -- are treated as a single separator. eg. -- --
--   tokens (=='a') "aabbaca" == ["bb","c"]
--   
tokens :: (Storable a) => (a -> Bool) -> Vector a -> [Vector a] -- | O(n) The join function takes a Vector and a list -- of Vectors and concatenates the list after interspersing the -- first argument between each element of the list. join :: (Storable a) => Vector a -> [Vector a] -> Vector a -- | O(n) The isPrefixOf function takes two Vector and -- returns True iff the first is a prefix of the second. isPrefixOf :: (Storable a, Eq a) => Vector a -> Vector a -> Bool -- | O(n) The isSuffixOf function takes two Vectors -- and returns True iff the first is a suffix of the second. -- -- The following holds: -- --
--   isSuffixOf x y == reverse x `isPrefixOf` reverse y
--   
isSuffixOf :: (Storable a, Eq a) => Vector a -> Vector a -> Bool -- | O(n) elem is the Vector membership predicate. elem :: (Storable a, Eq a) => a -> Vector a -> Bool -- | O(n) notElem is the inverse of elem notElem :: (Storable a, Eq a) => a -> Vector a -> Bool -- | O(n) The find function takes a predicate and a -- Vector, and returns the first element in matching the -- predicate, or Nothing if there is no such element. -- --
--   find f p = case findIndex f p of Just n -> Just (p ! n) ; _ -> Nothing
--   
find :: (Storable a) => (a -> Bool) -> Vector a -> Maybe a -- | O(n) filter, applied to a predicate and a Vector, -- returns a Vector containing those elements that satisfy the -- predicate. This function is subject to array fusion. filter :: (Storable a) => (a -> Bool) -> Vector a -> Vector a -- | O(1) Vector index (subscript) operator, starting from 0. index :: (Storable a) => Vector a -> Int -> a -- | O(n) The elemIndex function returns the index of the -- first element in the given Vector which is equal to the query -- element, or Nothing if there is no such element. elemIndex :: (Storable a, Eq a) => a -> Vector a -> Maybe Int -- | O(n) The elemIndices function extends elemIndex, -- by returning the indices of all elements equal to the query element, -- in ascending order. elemIndices :: (Storable a, Eq a) => a -> Vector a -> [Int] -- | O(n) The elemIndexEnd function returns the last index of -- the element in the given Vector which is equal to the query -- element, or Nothing if there is no such element. The following -- holds: -- --
--   elemIndexEnd c xs ==
--   (-) (length xs - 1) `fmap` elemIndex c (reverse xs)
--   
elemIndexEnd :: (Storable a, Eq a) => a -> Vector a -> Maybe Int -- | The findIndex function takes a predicate and a Vector -- and returns the index of the first element in the Vector -- satisfying the predicate. findIndex :: (Storable a) => (a -> Bool) -> Vector a -> Maybe Int -- | The findIndices function extends findIndex, by returning -- the indices of all elements satisfying the predicate, in ascending -- order. findIndices :: (Storable a) => (a -> Bool) -> Vector a -> [Int] -- | count returns the number of times its argument appears in the -- Vector -- --
--   count = length . elemIndices
--   
-- -- But more efficiently than using length on the intermediate list. count :: (Storable a, Eq a) => a -> Vector a -> Int -- | findIndexOrEnd is a variant of findIndex, that returns the -- length of the string if no element is found, rather than Nothing. findIndexOrEnd :: (Storable a) => (a -> Bool) -> Vector a -> Int -- | O(n) zip takes two Vectors and returns a list of -- corresponding pairs of elements. If one input Vector is short, -- excess elements of the longer Vector are discarded. This is -- equivalent to a pair of unpack operations. zip :: (Storable a, Storable b) => Vector a -> Vector b -> [(a, b)] -- | zipWith generalises zip by zipping with the function -- given as the first argument, instead of a tupling function. For -- example, zipWith (+) is applied to two Vectors -- to produce the list of corresponding sums. zipWith :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c -- | O(n) unzip transforms a list of pairs of elements into a -- pair of Vectors. Note that this performs two pack -- operations. unzip :: (Storable a, Storable b) => [(a, b)] -> (Vector a, Vector b) -- | O(n) Make a copy of the Vector with its own storage. -- This is mainly useful to allow the rest of the data pointed to by the -- Vector to be garbage collected, for example if a large string -- has been read in, and only a small part of it is needed in the rest of -- the program. copy :: (Storable a) => Vector a -> Vector a -- | Read a Vector directly from the specified Handle. This -- is far more efficient than reading the characters into a list and then -- using pack. hGet :: (Storable a) => Handle -> Int -> IO (Vector a) -- | Outputs a Vector to the specified Handle. hPut :: (Storable a) => Handle -> Vector a -> IO () -- | Read an entire file strictly into a Vector. This is far more -- efficient than reading the characters into a String and then -- using pack. It also may be more efficient than opening the file -- and reading it using hGet. Files are read using 'binary mode' on -- Windows. readFile :: (Storable a) => FilePath -> IO (Vector a) -- | Write a Vector to a file. writeFile :: (Storable a) => FilePath -> Vector a -> IO () -- | Append a Vector to a file. appendFile :: (Storable a) => FilePath -> Vector a -> IO () instance (Storable a) => Monoid (Vector a) instance (Storable a, Eq a) => Eq (Vector a) -- | Chunky signal stream build on StorableVector. -- -- Hints for fusion: - Higher order functions should always be inlined in -- the end in order to turn them into machine loops instead of calling a -- function in an inner loop. module Data.StorableVector.Lazy newtype Vector a SV :: [Vector a] -> Vector a chunks :: Vector a -> [Vector a] newtype ChunkSize ChunkSize :: Int -> ChunkSize chunkSize :: Int -> ChunkSize defaultChunkSize :: ChunkSize empty :: (Storable a) => Vector a singleton :: (Storable a) => a -> Vector a fromChunks :: (Storable a) => [Vector a] -> Vector a pack :: (Storable a) => ChunkSize -> [a] -> Vector a unpack :: (Storable a) => Vector a -> [a] packWith :: (Storable b) => ChunkSize -> (a -> b) -> [a] -> Vector b unpackWith :: (Storable a) => (a -> b) -> Vector a -> [b] unfoldr :: (Storable b) => ChunkSize -> (a -> Maybe (b, a)) -> a -> Vector b sample :: (Storable a) => ChunkSize -> (Int -> a) -> Vector a sampleN :: (Storable a) => ChunkSize -> Int -> (Int -> a) -> Vector a iterate :: (Storable a) => ChunkSize -> (a -> a) -> a -> Vector a repeat :: (Storable a) => ChunkSize -> a -> Vector a cycle :: (Storable a) => Vector a -> Vector a replicate :: (Storable a) => ChunkSize -> Int -> a -> Vector a null :: (Storable a) => Vector a -> Bool length :: Vector a -> Int equal :: (Storable a, Eq a) => Vector a -> Vector a -> Bool index :: (Storable a) => Vector a -> Int -> a cons :: (Storable a) => a -> Vector a -> Vector a append :: (Storable a) => Vector a -> Vector a -> Vector a -- | extendL size x y prepends the chunk x and merges it -- with the first chunk of y if the total size is at most -- size. This way you can prepend small chunks while asserting a -- reasonable average size for chunks. extendL :: (Storable a) => ChunkSize -> Vector a -> Vector a -> Vector a concat :: (Storable a) => [Vector a] -> Vector a map :: (Storable x, Storable y) => (x -> y) -> Vector x -> Vector y reverse :: (Storable a) => Vector a -> Vector a foldl :: (Storable b) => (a -> b -> a) -> a -> Vector b -> a foldl' :: (Storable b) => (a -> b -> a) -> a -> Vector b -> a foldr :: (Storable b) => (b -> a -> a) -> a -> Vector b -> a any :: (Storable a) => (a -> Bool) -> Vector a -> Bool all :: (Storable a) => (a -> Bool) -> Vector a -> Bool maximum :: (Storable a, Ord a) => Vector a -> a minimum :: (Storable a, Ord a) => Vector a -> a pointer :: (Storable a) => Vector a -> Pointer a viewL :: (Storable a) => Vector a -> Maybe (a, Vector a) viewR :: (Storable a) => Vector a -> Maybe (Vector a, a) switchL :: (Storable a) => b -> (a -> Vector a -> b) -> Vector a -> b switchR :: (Storable a) => b -> (Vector a -> a -> b) -> Vector a -> b scanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a mapAccumL :: (Storable a, Storable b) => (acc -> a -> (acc, b)) -> acc -> Vector a -> (acc, Vector b) mapAccumR :: (Storable a, Storable b) => (acc -> a -> (acc, b)) -> acc -> Vector a -> (acc, Vector b) crochetLChunk :: (Storable x, Storable y) => (x -> acc -> Maybe (y, acc)) -> acc -> Vector x -> (Vector y, Maybe acc) crochetL :: (Storable x, Storable y) => (x -> acc -> Maybe (y, acc)) -> acc -> Vector x -> Vector y take :: (Storable a) => Int -> Vector a -> Vector a drop :: (Storable a) => Int -> Vector a -> Vector a splitAt :: (Storable a) => Int -> Vector a -> (Vector a, Vector a) -- | dropMarginRem n m xs drops at most the first m -- elements of xs and ensures that xs still contains -- n elements. Additionally returns the number of elements that -- could not be dropped due to the margin constraint. That is -- dropMarginRem n m xs == (k,ys) implies length xs - m == -- length ys - k. Requires length xs >= n. dropMarginRem :: (Storable a) => Int -> Int -> Vector a -> (Int, Vector a) dropMargin :: (Storable a) => Int -> Int -> Vector a -> Vector a dropWhile :: (Storable a) => (a -> Bool) -> Vector a -> Vector a takeWhile :: (Storable a) => (a -> Bool) -> Vector a -> Vector a span :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) filter :: (Storable a) => (a -> Bool) -> Vector a -> Vector a zipWith :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c zipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> (Vector a -> Vector b -> Vector c -> Vector d) zipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => (a -> b -> c -> d -> e) -> (Vector a -> Vector b -> Vector c -> Vector d -> Vector e) zipWithSize :: (Storable a, Storable b, Storable c) => ChunkSize -> (a -> b -> c) -> Vector a -> Vector b -> Vector c zipWithSize3 :: (Storable a, Storable b, Storable c, Storable d) => ChunkSize -> (a -> b -> c -> d) -> (Vector a -> Vector b -> Vector c -> Vector d) zipWithSize4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => ChunkSize -> (a -> b -> c -> d -> e) -> (Vector a -> Vector b -> Vector c -> Vector d -> Vector e) -- | Ensure a minimal length of the list by appending pad values. pad :: (Storable a) => ChunkSize -> a -> Int -> Vector a -> Vector a padAlt :: (Storable a) => ChunkSize -> a -> Int -> Vector a -> Vector a cancelNullVector :: (Vector a, b) -> Maybe (Vector a, b) fromChunk :: (Storable a) => Vector a -> Vector a -- | Read the rest of a file lazily and provide the reason of termination -- as IOError. If IOError is EOF (check with System.Error.isEOFError -- err), then the file was read successfully. Only access the final -- IOError after you have consumed the file contents, since finding out -- the terminating reason forces to read the entire file. Make also sure -- you read the file completely, because it is only closed when the file -- end is reached (or an exception is encountered). -- -- TODO: In ByteString.Lazy the chunk size is reduced if data is not -- immediately available. Maybe we should adapt that behaviour but when -- working with realtime streams that may mean that the chunks are very -- small. hGetContentsAsync :: (Storable a) => ChunkSize -> Handle -> IO (IOError, Vector a) hPut :: (Storable a) => Handle -> Vector a -> IO () -- | The file can only closed after all values are consumed. That is you -- must always assert that you consume all elements of the stream, and -- that no values are missed due to lazy evaluation. This requirement -- makes this function useless in many applications. readFileAsync :: (Storable a) => ChunkSize -> FilePath -> IO (IOError, Vector a) writeFile :: (Storable a) => FilePath -> Vector a -> IO () appendFile :: (Storable a) => FilePath -> Vector a -> IO () moduleError :: String -> String -> a instance Eq ChunkSize instance Ord ChunkSize instance Show ChunkSize instance C ChunkSize instance Num ChunkSize instance (Storable a, Eq a) => Eq (Vector a) instance (Storable a) => Monoid (Vector a) -- | In principle you can traverse through a lazy storable vector using -- repeated calls to viewL. However this needs a bit of pointer -- arrangement and allocation. This data structure makes the inner loop -- faster, that consists of traversing through a chunk. module Data.StorableVector.Lazy.Pointer data Pointer a cons :: (Storable a) => Vector a -> Pointer a viewL :: (Storable a) => Pointer a -> Maybe (a, Pointer a) switchL :: (Storable a) => b -> (a -> Pointer a -> b) -> Pointer a -> b -- | Functions for StorableVector that allow control of the size -- of individual chunks. -- -- This is import for an application like the following: You want to mix -- audio signals that are relatively shifted. The structure of chunks of -- three streams may be illustrated as: -- --
--   [____] [____] [____] [____] ...
--     [____] [____] [____] [____] ...
--       [____] [____] [____] [____] ...
--   
-- -- When we mix the streams (zipWith3 (x y z -> x+y+z)) with -- respect to the chunk structure of the first signal, computing the -- first chunk requires full evaluation of all leading chunks of the -- stream. However the last value of the third leading chunk is much -- later in time than the last value of the first leading chunk. We like -- to reduce these dependencies using a different chunk structure, say -- --
--   [____] [____] [____] [____] ...
--     [__] [____] [____] [____] ...
--       [] [____] [____] [____] ...
--   
module Data.StorableVector.Lazy.Pattern data Vector a data ChunkSize chunkSize :: Int -> ChunkSize defaultChunkSize :: ChunkSize type LazySize = T ChunkSize empty :: (Storable a) => Vector a singleton :: (Storable a) => a -> Vector a pack :: (Storable a) => LazySize -> [a] -> Vector a unpack :: (Storable a) => Vector a -> [a] packWith :: (Storable b) => LazySize -> (a -> b) -> [a] -> Vector b unpackWith :: (Storable a) => (a -> b) -> Vector a -> [b] unfoldrN :: (Storable b) => LazySize -> (a -> Maybe (b, a)) -> a -> (Vector b, Maybe a) iterateN :: (Storable a) => LazySize -> (a -> a) -> a -> Vector a cycle :: (Storable a) => Vector a -> Vector a replicate :: (Storable a) => LazySize -> a -> Vector a null :: (Storable a) => Vector a -> Bool length :: Vector a -> LazySize cons :: (Storable a) => a -> Vector a -> Vector a append :: (Storable a) => Vector a -> Vector a -> Vector a concat :: (Storable a) => [Vector a] -> Vector a map :: (Storable x, Storable y) => (x -> y) -> Vector x -> Vector y reverse :: (Storable a) => Vector a -> Vector a foldl :: (Storable b) => (a -> b -> a) -> a -> Vector b -> a foldl' :: (Storable b) => (a -> b -> a) -> a -> Vector b -> a any :: (Storable a) => (a -> Bool) -> Vector a -> Bool all :: (Storable a) => (a -> Bool) -> Vector a -> Bool maximum :: (Storable a, Ord a) => Vector a -> a minimum :: (Storable a, Ord a) => Vector a -> a viewL :: (Storable a) => Vector a -> Maybe (a, Vector a) viewR :: (Storable a) => Vector a -> Maybe (Vector a, a) switchL :: (Storable a) => b -> (a -> Vector a -> b) -> Vector a -> b switchR :: (Storable a) => b -> (Vector a -> a -> b) -> Vector a -> b scanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a mapAccumL :: (Storable a, Storable b) => (acc -> a -> (acc, b)) -> acc -> Vector a -> (acc, Vector b) mapAccumR :: (Storable a, Storable b) => (acc -> a -> (acc, b)) -> acc -> Vector a -> (acc, Vector b) crochetL :: (Storable x, Storable y) => (x -> acc -> Maybe (y, acc)) -> acc -> Vector x -> Vector y take :: (Storable a) => LazySize -> Vector a -> Vector a drop :: (Storable a) => LazySize -> Vector a -> Vector a splitAt :: (Storable a) => LazySize -> Vector a -> (Vector a, Vector a) -- | dropMarginRem n m xs drops at most the first m -- elements of xs and ensures that xs still contains -- n elements. Additionally returns the number of elements that -- could not be dropped due to the margin constraint. That is -- dropMarginRem n m xs == (k,ys) implies length xs - m == -- length ys - k. Requires length xs >= n. dropMarginRem :: (Storable a) => Int -> Int -> Vector a -> (Int, Vector a) dropMargin :: (Storable a) => Int -> Int -> Vector a -> Vector a dropWhile :: (Storable a) => (a -> Bool) -> Vector a -> Vector a takeWhile :: (Storable a) => (a -> Bool) -> Vector a -> Vector a span :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) filter :: (Storable a) => (a -> Bool) -> Vector a -> Vector a zipWith :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c zipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> (Vector a -> Vector b -> Vector c -> Vector d) zipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => (a -> b -> c -> d -> e) -> (Vector a -> Vector b -> Vector c -> Vector d -> Vector e) zipWithSize :: (Storable a, Storable b, Storable c) => LazySize -> (a -> b -> c) -> Vector a -> Vector b -> Vector c zipWithSize3 :: (Storable a, Storable b, Storable c, Storable d) => LazySize -> (a -> b -> c -> d) -> (Vector a -> Vector b -> Vector c -> Vector d) zipWithSize4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => LazySize -> (a -> b -> c -> d -> e) -> (Vector a -> Vector b -> Vector c -> Vector d -> Vector e) -- | Tested with : GHC 6.4.1 -- -- Interface for access to a mutable StorableVector. module Data.StorableVector.ST.Strict data Vector s a new :: (Storable e) => Int -> e -> ST s (Vector s e) new_ :: (Storable e) => Int -> ST s (Vector s e) -- |
--   Control.Monad.ST.runST (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; read arr 3)
--   
read :: (Storable e) => Vector s e -> Int -> ST s e -- |
--   VS.unpack $ runSTVector (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; return arr)
--   
write :: (Storable e) => Vector s e -> Int -> e -> ST s () -- |
--   VS.unpack $ runSTVector (do arr <- new 10 'a'; Monad.mapM_ (\n -> modify arr (mod n 8) succ) [0..10]; return arr)
--   
modify :: (Storable e) => Vector s e -> Int -> (e -> e) -> ST s () freeze :: (Storable e) => Vector s e -> ST s (Vector e) thaw :: (Storable e) => Vector e -> ST s (Vector s e) length :: Vector s e -> Int runSTVector :: (Storable e) => (forall s. ST s (Vector s e)) -> Vector e -- |
--   :module + Data.STRef
--   VS.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapST (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VS.pack [1,2,3,4::Data.Int.Int16]))
--   
mapST :: (Storable a, Storable b) => (a -> ST s b) -> Vector a -> ST s (Vector b) -- |
--   *Data.StorableVector.ST.Strict Data.STRef> VL.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapSTLazy (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VL.pack VL.defaultChunkSize [1,2,3,4::Data.Int.Int16]))
--   "abcd"
--   
-- -- The following should not work on infinite streams, since we are in -- ST with strict >>=. But it works. Why? -- --
--   *Data.StorableVector.ST.Strict Data.STRef> VL.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapSTLazy (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VL.pack VL.defaultChunkSize [0::Data.Int.Int16 ..]))
--   "Interrupted.
--   
mapSTLazy :: (Storable a, Storable b) => (a -> ST s b) -> Vector a -> ST s (Vector b) -- | Tested with : GHC 6.4.1 -- -- Interface for access to a mutable StorableVector. module Data.StorableVector.ST.Lazy data Vector s a new :: (Storable e) => Int -> e -> ST s (Vector s e) new_ :: (Storable e) => Int -> ST s (Vector s e) -- |
--   Control.Monad.ST.runST (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; read arr 3)
--   
read :: (Storable e) => Vector s e -> Int -> ST s e -- |
--   VS.unpack $ runSTVector (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; return arr)
--   
write :: (Storable e) => Vector s e -> Int -> e -> ST s () modify :: (Storable e) => Vector s e -> Int -> (e -> e) -> ST s () freeze :: (Storable e) => Vector s e -> ST s (Vector e) thaw :: (Storable e) => Vector e -> ST s (Vector s e) length :: Vector s e -> Int runSTVector :: (Storable e) => (forall s. ST s (Vector s e)) -> Vector e -- |
--   :module + Data.STRef
--   VS.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapST (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VS.pack [1,2,3,4::Data.Int.Int16]))
--   
mapST :: (Storable a, Storable b) => (a -> ST s b) -> Vector a -> ST s (Vector b) -- |
--   *Data.StorableVector.ST.Strict Data.STRef> VL.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapSTLazy (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VL.pack VL.defaultChunkSize [1,2,3,4::Data.Int.Int16]))
--   "abcd"
--   
-- -- The following should not work on infinite streams, since we are in -- ST with strict >>=. But it works. Why? -- --
--   *Data.StorableVector.ST.Strict Data.STRef.Lazy> VL.unpack $ Control.Monad.ST.Lazy.runST (do ref <- newSTRef 'a'; mapSTLazy (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VL.pack VL.defaultChunkSize [0::Data.Int.Int16 ..]))
--   "Interrupted.
--   
mapSTLazy :: (Storable a, Storable b) => (a -> ST s b) -> Vector a -> ST s (Vector b) -- | Build a lazy storable vector by incrementally adding an element. This -- is analogous to Data.Binary.Builder for Data.ByteString.Lazy. module Data.StorableVector.Lazy.Builder data Builder a toLazyStorableVector :: (Storable a) => ChunkSize -> Builder a -> Vector a put :: (Storable a) => a -> Builder a -- | Set a laziness break. flush :: (Storable a) => Builder a instance (Storable a) => Monoid (Builder a)