-- 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 package -- http://hackage.haskell.org/package/vector with a similar -- intention. -- -- We do not provide advanced fusion optimization, since especially for -- lazy vectors this would either be incorrect or not applicable. However -- we provide fusion with lazy lists in the package -- http://hackage.haskell.org/package/storablevector-streamfusion. @package storablevector @version 0.2.13 -- | 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 :: {-# UNPACK #-} !(ForeignPtr a) -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !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 incPtr :: (Storable a) => Ptr a -> Ptr a -- | Just like Unsafe.performIO, 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 -- Unsafe.performIO. inlinePerformIO :: IO a -> a instance Data.Data.Data a => Data.Data.Data (Data.StorableVector.Base.Vector a) instance Foreign.Storable.Storable a => Control.DeepSeq.NFData (Data.StorableVector.Base.Vector a) instance (Foreign.Storable.Storable a, GHC.Show.Show a) => GHC.Show.Show (Data.StorableVector.Base.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. It is a checked error to pass 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. It is a checked error to pass 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. It is a checked error to pass an empty -- Vector. tail :: (Storable a) => Vector a -> Vector a -- | O(1) Return all the elements of a Vector except the last -- one. It is a checked error to pass 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) map functions, provided with the index at each position mapIndexed :: (Storable a, Storable b) => (Int -> 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. 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. It is -- a checked error to pass an empty Vector. foldl1 :: (Storable a) => (a -> a -> a) -> Vector a -> a -- | 'foldl1\'' is like foldl1, but strict in the accumulator. It is -- a checked error to pass 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. However, it is not the same as foldl applied to the -- reversed vector. Actually foldr starts processing with the -- first element, and thus can be used for efficiently building a singly -- linked list by foldr (:) [] vec. Unfortunately foldr -- is quite slow for low-level loops, since GHC (up to 6.12.1) cannot -- detect the loop. 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 It is a -- checked error to pass 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 -- | This is like mconcat . map f, but in many cases the result of -- f will not be storable. foldMap :: (Storable a, Monoid m) => (a -> m) -> Vector a -> m -- | Deprecated: Use foldMap instead. monoidConcatMap :: (Storable a, Monoid m) => (a -> m) -> Vector a -> m -- | 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. It is a checked error to pass -- 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. It is a checked error to pass -- 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) crochetL :: (Storable x, Storable y) => (x -> acc -> Maybe (y, acc)) -> acc -> Vector x -> Vector y crochetLResult :: (Storable x, Storable y) => (x -> acc -> Maybe (y, acc)) -> acc -> Vector x -> (Vector y, Maybe acc) -- | 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) iterateN n f x is a Vector of -- length n where the elements of x are generated by -- repeated application of f. iterateN :: (Storable a) => Int -> (a -> a) -> 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) Like unfoldrN this function builds a Vector -- from a seed value with limited size. Additionally it returns a value, -- that depends on the state, but is not necessarily the state itself. If -- end of vector and end of the generator coincide, then the result is as -- if only the end of vector is reached. -- -- Example: -- --
--   unfoldrResultN 30 Char.ord (\c -> if c>'z' then Left 1000 else Right (c, succ c)) 'a'
--   
-- -- The following equation relates unfoldrN and -- unfoldrResultN: -- --
--   unfoldrN n f s ==
--      unfoldrResultN n Just
--         (maybe (Left Nothing) Right . f) s
--   
-- -- It is not possible to express unfoldrResultN in terms of -- unfoldrN. unfoldrResultN :: (Storable b) => Int -> (a -> c) -> (a -> Either c (b, a)) -> a -> (Vector b, c) -- | 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 empty 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] -- | sliceVertical n xs divides vector in chunks of size -- n. Requires time proportionally to length of result list, -- i.e. ceiling (length xs / n). sliceVertical :: (Storable a) => Int -> 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. 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 -- | Like zipWith but for three input vectors zipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d -- | Like zipWith but for four input vectors If you need even more -- input vectors, you might write a function yourselve using unfoldrN and -- viewL. 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 -- | 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 -- | O(ln)/ sieve selects every nth element. sieve :: (Storable a) => Int -> Vector a -> Vector a -- | O(n) Returns n sieved vectors with successive starting -- elements. deinterleave 3 (pack ['a'..'k']) = [pack "adgj", pack -- "behk", pack "cfi"] This is the same as sliceHorizontal. deinterleave :: (Storable a) => Int -> Vector a -> [Vector a] -- | O(n) Almost the inverse of deinterleave. Restriction is that -- all input vector must have equal length. interleave [pack "adgj", -- pack "behk", pack "cfil"] = pack ['a'..'l'] interleave :: (Storable a) => [Vector a] -> Vector a -- | Write a Vector to a contiguous piece of memory. poke :: (Storable a) => Ptr a -> Vector a -> IO () -- | Read a Vector from a contiguous piece of memory. peek :: (Storable a) => Int -> Ptr a -> IO (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 (Foreign.Storable.Storable a, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.StorableVector.Base.Vector a) instance Foreign.Storable.Storable a => Data.Semigroup.Semigroup (Data.StorableVector.Base.Vector a) instance Foreign.Storable.Storable a => GHC.Base.Monoid (Data.StorableVector.Base.Vector a) instance (Foreign.Storable.Storable a, Test.QuickCheck.Arbitrary.Arbitrary a) => Test.QuickCheck.Arbitrary.Arbitrary (Data.StorableVector.Base.Vector a) -- | In principle you can traverse through a storable vector using repeated -- calls to viewL or using index. However this needs a -- bit of pointer arrangement and allocation. This data structure should -- make loops optimally fast. module Data.StorableVector.Pointer -- | We might have name the data type iterator. data Pointer a Pointer :: {-# UNPACK #-} !(ForeignPtr a) -> {-# UNPACK #-} !(Ptr a) -> {-# UNPACK #-} !Int -> Pointer a [fptr] :: Pointer a -> {-# UNPACK #-} !(ForeignPtr a) [ptr] :: Pointer a -> {-# UNPACK #-} !(Ptr a) [left] :: Pointer a -> {-# UNPACK #-} !Int 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 -- | Chunky signal stream built 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] -- | Warning: It seems to be used nowhere and might be removed. packWith :: (Storable b) => ChunkSize -> (a -> b) -> [a] -> Vector b -- | Warning: It seems to be used nowhere and might be removed. unpackWith :: (Storable a) => (a -> b) -> Vector a -> [b] unfoldr :: (Storable b) => ChunkSize -> (a -> Maybe (b, a)) -> a -> Vector b -- | Example: -- --
--   *Data.StorableVector.Lazy> unfoldrResult (ChunkSize 5) (\c -> if c>'z' then Left (Char.ord c) else Right (c, succ c)) 'a'
--   (VectorLazy.fromChunks [Vector.pack "abcde",Vector.pack "fghij",Vector.pack "klmno",Vector.pack "pqrst",Vector.pack "uvwxy",Vector.pack "z"],123)
--   
unfoldrResult :: (Storable b) => ChunkSize -> (a -> Either c (b, a)) -> a -> (Vector b, c) 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 infixr 5 `append` -- | 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 sliceVertical :: (Storable a) => Int -> Vector a -> [Vector a] snoc :: Storable a => Vector a -> 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 foldMap :: (Storable a, Monoid m) => (a -> m) -> Vector a -> m -- | Deprecated: Use foldMap instead. monoidConcatMap :: (Storable a, Monoid m) => (a -> m) -> Vector a -> m 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) crochetL :: (Storable x, Storable y) => (x -> acc -> Maybe (y, acc)) -> acc -> Vector x -> Vector y take :: (Storable a) => Int -> Vector a -> Vector a -- | Take n values from the end of the vector in a memory friendly way. -- takeEnd n xs should perform the same as drop (length xs - -- n) xs, but the latter one would have to materialise xs -- completely. In contrast to that takeEnd should hold only -- chunks of about n elements at any time point. takeEnd :: (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 -- | Generates laziness breaks wherever one of the input signals has a -- chunk boundary. 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 zipWithAppend :: (Storable a) => (a -> a -> a) -> Vector a -> Vector a -> Vector a -- | Preserves chunk pattern of the last argument. zipWithLastPattern :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c -- | Preserves chunk pattern of the last argument. zipWithLastPattern3 :: (Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> (Vector a -> Vector b -> Vector c -> Vector d) -- | Preserves chunk pattern of the last argument. zipWithLastPattern4 :: (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) sieve :: (Storable a) => Int -> Vector a -> Vector a deinterleave :: (Storable a) => Int -> Vector a -> [Vector a] -- | Interleave lazy vectors while maintaining the chunk pattern of the -- first vector. All input vectors must have the same length. interleaveFirstPattern :: (Storable a) => [Vector a] -> Vector a -- | Ensure a minimal length of the list by appending pad values. pad :: (Storable a) => ChunkSize -> a -> Int -> Vector a -> Vector a compact :: (Storable a) => ChunkSize -> Vector a -> Vector a 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) hGetContentsSync :: Storable a => ChunkSize -> Handle -> IO (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 () interact :: Storable a => ChunkSize -> (Vector a -> Vector a) -> IO () -- | Deprecated: Use Storable.Vector.crochetLResult crochetLChunk :: (Storable x, Storable y) => (x -> acc -> Maybe (y, acc)) -> acc -> Vector x -> (Vector y, Maybe acc) -- | Warning: use pad instead padAlt :: (Storable a) => ChunkSize -> a -> Int -> Vector a -> Vector a -- | Warning: do not use it cancelNullVector :: (Vector a, b) -> Maybe (Vector a, b) moduleError :: String -> String -> a instance GHC.Show.Show Data.StorableVector.Lazy.ChunkSize instance GHC.Classes.Ord Data.StorableVector.Lazy.ChunkSize instance GHC.Classes.Eq Data.StorableVector.Lazy.ChunkSize instance Test.QuickCheck.Arbitrary.Arbitrary Data.StorableVector.Lazy.ChunkSize instance GHC.Num.Num Data.StorableVector.Lazy.ChunkSize instance Data.Semigroup.Semigroup Data.StorableVector.Lazy.ChunkSize instance GHC.Base.Monoid Data.StorableVector.Lazy.ChunkSize instance Numeric.NonNegative.Class.C Data.StorableVector.Lazy.ChunkSize instance Foreign.Storable.Storable a => Data.Semigroup.Semigroup (Data.StorableVector.Lazy.Vector a) instance Foreign.Storable.Storable a => GHC.Base.Monoid (Data.StorableVector.Lazy.Vector a) instance (Foreign.Storable.Storable a, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.StorableVector.Lazy.Vector a) instance (Foreign.Storable.Storable a, GHC.Show.Show a) => GHC.Show.Show (Data.StorableVector.Lazy.Vector a) instance (Foreign.Storable.Storable a, Test.QuickCheck.Arbitrary.Arbitrary a) => Test.QuickCheck.Arbitrary.Arbitrary (Data.StorableVector.Lazy.Vector a) instance Foreign.Storable.Storable a => Control.DeepSeq.NFData (Data.StorableVector.Lazy.Vector a) -- | Like Data.StorableVector.Lazy but the maximum chunk size is -- encoded in a type parameter. This way, you do not need to pass a chunk -- size parameter at various places. The API becomes more like the one -- for lists and ByteStrings. module Data.StorableVector.Lazy.Typed -- | A Vector size a represents a chunky storable vector with -- maximum chunk size expressed by type parameter size. data Vector size a type DefaultVector = Vector DefaultChunkSize class Size size chunkSize :: Size size => ChunkSize size data ChunkSize size chunkSize :: Size size => ChunkSize size lazyChunkSize :: ChunkSize size -> ChunkSize type DefaultChunkSize = Size1024 data Size1024 empty :: (Storable a) => Vector size a singleton :: (Storable a) => a -> Vector size a toVectorLazy :: Vector size a -> Vector a -- | This will maintain all laziness breaks, but if chunks are too big, -- they will be split. fromVectorLazy :: (Size size, Storable a) => Vector a -> Vector size a chunks :: Vector size a -> [Vector a] fromChunks :: (Size size, Storable a) => [Vector a] -> Vector size a pack :: (Size size, Storable a) => [a] -> Vector size a unpack :: (Storable a) => Vector size a -> [a] unfoldr :: (Size size, Storable b) => (a -> Maybe (b, a)) -> a -> Vector size b unfoldrResult :: (Size size, Storable b) => (a -> Either c (b, a)) -> a -> (Vector size b, c) sample :: (Size size, Storable a) => (Int -> a) -> Vector size a sampleN :: (Size size, Storable a) => Int -> (Int -> a) -> Vector size a iterate :: (Size size, Storable a) => (a -> a) -> a -> Vector size a repeat :: (Size size, Storable a) => a -> Vector size a cycle :: (Size size, Storable a) => Vector size a -> Vector size a replicate :: (Size size, Storable a) => Int -> a -> Vector size a null :: (Size size, Storable a) => Vector size a -> Bool length :: Vector size a -> Int equal :: (Size size, Storable a, Eq a) => Vector size a -> Vector size a -> Bool index :: (Size size, Storable a) => Vector size a -> Int -> a cons :: (Size size, Storable a) => a -> Vector size a -> Vector size a append :: (Size size, Storable a) => Vector size a -> Vector size a -> Vector size a infixr 5 `append` -- | extendL 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. The prepended chunk must be -- smaller than the maximum chunk size in the Vector. This is not -- checked. extendL :: (Size size, Storable a) => Vector a -> Vector size a -> Vector size a concat :: (Size size, Storable a) => [Vector size a] -> Vector size a sliceVertical :: (Size size, Storable a) => Int -> Vector size a -> [Vector size a] snoc :: (Size size, Storable a) => Vector size a -> a -> Vector size a map :: (Size size, Storable x, Storable y) => (x -> y) -> Vector size x -> Vector size y reverse :: (Size size, Storable a) => Vector size a -> Vector size a foldl :: (Size size, Storable b) => (a -> b -> a) -> a -> Vector size b -> a foldl' :: (Size size, Storable b) => (a -> b -> a) -> a -> Vector size b -> a foldr :: (Size size, Storable b) => (b -> a -> a) -> a -> Vector size b -> a foldMap :: (Size size, Storable a, Monoid m) => (a -> m) -> Vector size a -> m any :: (Size size, Storable a) => (a -> Bool) -> Vector size a -> Bool all :: (Size size, Storable a) => (a -> Bool) -> Vector size a -> Bool maximum :: (Size size, Storable a, Ord a) => Vector size a -> a minimum :: (Size size, Storable a, Ord a) => Vector size a -> a viewL :: (Size size, Storable a) => Vector size a -> Maybe (a, Vector size a) viewR :: (Size size, Storable a) => Vector size a -> Maybe (Vector size a, a) switchL :: (Size size, Storable a) => b -> (a -> Vector size a -> b) -> Vector size a -> b switchR :: (Size size, Storable a) => b -> (Vector size a -> a -> b) -> Vector size a -> b scanl :: (Size size, Storable a, Storable b) => (a -> b -> a) -> a -> Vector size b -> Vector size a mapAccumL :: (Size size, Storable a, Storable b) => (acc -> a -> (acc, b)) -> acc -> Vector size a -> (acc, Vector size b) mapAccumR :: (Size size, Storable a, Storable b) => (acc -> a -> (acc, b)) -> acc -> Vector size a -> (acc, Vector size b) crochetL :: (Size size, Storable x, Storable y) => (x -> acc -> Maybe (y, acc)) -> acc -> Vector size x -> Vector size y take :: (Size size, Storable a) => Int -> Vector size a -> Vector size a takeEnd :: (Size size, Storable a) => Int -> Vector size a -> Vector size a drop :: (Size size, Storable a) => Int -> Vector size a -> Vector size a splitAt :: (Size size, Storable a) => Int -> Vector size a -> (Vector size a, Vector size a) dropMarginRem :: (Size size, Storable a) => Int -> Int -> Vector size a -> (Int, Vector size a) dropMargin :: (Size size, Storable a) => Int -> Int -> Vector size a -> Vector size a dropWhile :: (Size size, Storable a) => (a -> Bool) -> Vector size a -> Vector size a takeWhile :: (Size size, Storable a) => (a -> Bool) -> Vector size a -> Vector size a span :: (Size size, Storable a) => (a -> Bool) -> Vector size a -> (Vector size a, Vector size a) filter :: (Size size, Storable a) => (a -> Bool) -> Vector size a -> Vector size a -- | Generates laziness breaks wherever one of the input signals has a -- chunk boundary. zipWith :: (Size size, Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector size a -> Vector size b -> Vector size c zipWith3 :: (Size size, Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> Vector size a -> Vector size b -> Vector size c -> Vector size d zipWith4 :: (Size size, Storable a, Storable b, Storable c, Storable d, Storable e) => (a -> b -> c -> d -> e) -> Vector size a -> Vector size b -> Vector size c -> Vector size d -> Vector size e zipWithAppend :: (Size size, Storable a) => (a -> a -> a) -> Vector size a -> Vector size a -> Vector size a -- | Preserves chunk pattern of the last argument. zipWithLastPattern :: (Size size, Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector size a -> Vector size b -> Vector size c -- | Preserves chunk pattern of the last argument. zipWithLastPattern3 :: (Size size, Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> (Vector size a -> Vector size b -> Vector size c -> Vector size d) -- | Preserves chunk pattern of the last argument. zipWithLastPattern4 :: (Size size, Storable a, Storable b, Storable c, Storable d, Storable e) => (a -> b -> c -> d -> e) -> (Vector size a -> Vector size b -> Vector size c -> Vector size d -> Vector size e) zipWithSize :: (Size size, Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector size a -> Vector size b -> Vector size c zipWithSize3 :: (Size size, Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> (Vector size a -> Vector size b -> Vector size c -> Vector size d) zipWithSize4 :: (Size size, Storable a, Storable b, Storable c, Storable d, Storable e) => (a -> b -> c -> d -> e) -> (Vector size a -> Vector size b -> Vector size c -> Vector size d -> Vector size e) sieve :: (Size size, Storable a) => Int -> Vector size a -> Vector size a deinterleave :: (Size size, Storable a) => Int -> Vector size a -> [Vector size a] -- | Interleave lazy vectors while maintaining the chunk pattern of the -- first vector. All input vectors must have the same length. interleaveFirstPattern :: (Size size, Storable a) => [Vector size a] -> Vector size a -- | Ensure a minimal length of the list by appending pad values. pad :: (Size size, Storable a) => a -> Int -> Vector size a -> Vector size a hGetContentsAsync :: (Size size, Storable a) => Handle -> IO (IOError, Vector size a) hGetContentsSync :: (Size size, Storable a) => Handle -> IO (Vector size a) hPut :: (Size size, Storable a) => Handle -> Vector size a -> IO () readFileAsync :: (Size size, Storable a) => FilePath -> IO (IOError, Vector size a) writeFile :: (Size size, Storable a) => FilePath -> Vector size a -> IO () appendFile :: (Size size, Storable a) => FilePath -> Vector size a -> IO () interact :: (Size size, Storable a) => (Vector size a -> Vector size a) -> IO () instance Data.StorableVector.Lazy.Typed.Size Data.StorableVector.Lazy.Typed.Size1024 instance (Data.StorableVector.Lazy.Typed.Size size, Foreign.Storable.Storable a) => Data.Semigroup.Semigroup (Data.StorableVector.Lazy.Typed.Vector size a) instance (Data.StorableVector.Lazy.Typed.Size size, Foreign.Storable.Storable a) => GHC.Base.Monoid (Data.StorableVector.Lazy.Typed.Vector size a) instance (Data.StorableVector.Lazy.Typed.Size size, Foreign.Storable.Storable a, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.StorableVector.Lazy.Typed.Vector size a) instance (Data.StorableVector.Lazy.Typed.Size size, Foreign.Storable.Storable a, GHC.Show.Show a) => GHC.Show.Show (Data.StorableVector.Lazy.Typed.Vector size a) instance (Data.StorableVector.Lazy.Typed.Size size, Foreign.Storable.Storable a, Test.QuickCheck.Arbitrary.Arbitrary a) => Test.QuickCheck.Arbitrary.Arbitrary (Data.StorableVector.Lazy.Typed.Vector size a) instance (Data.StorableVector.Lazy.Typed.Size size, Foreign.Storable.Storable a) => Control.DeepSeq.NFData (Data.StorableVector.Lazy.Typed.Vector size 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 -- | Warning: It seems to be used nowhere and might be removed. 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 infixr 5 `append` 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 -- | Generates laziness breaks wherever either the lazy length number or -- the vector has a chunk boundary. 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) -- | Preserves the chunk pattern of the lazy vector. takeVectorPattern :: (Storable a) => LazySize -> Vector a -> Vector a splitAtVectorPattern :: (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 -- | Generates laziness breaks wherever one of the input signals has a -- chunk boundary. 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 () -- | Returns Just e, when the element e could be read and -- Nothing if the index was out of range. This way you can avoid -- duplicate index checks that may be needed when using read. -- --
--   Control.Monad.ST.runST (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; read arr 3)
--   
-- -- In future maybeRead will replace read. maybeRead :: (Storable e) => Vector s e -> Int -> ST s (Maybe e) -- | Returns True if the element could be written and False -- if the index was out of range. -- --
--   runSTVector (do arr <- new_ 10; foldr (\c go i -> maybeWrite arr i c >>= \cont -> if cont then go (succ i) else return arr) (error "unreachable") ['a'..] 0)
--   
-- -- In future maybeWrite will replace write. maybeWrite :: (Storable e) => Vector s e -> Int -> e -> ST s Bool -- | Similar to maybeWrite. -- -- In future maybeModify will replace modify. maybeModify :: (Storable e) => Vector s e -> Int -> (e -> e) -> ST s Bool unsafeRead :: (Storable e) => Vector s e -> Int -> ST s e unsafeWrite :: (Storable e) => Vector s e -> Int -> e -> ST s () unsafeModify :: (Storable e) => Vector s e -> Int -> (e -> e) -> ST s () freeze :: (Storable e) => Vector s e -> ST s (Vector e) -- | This is like freeze but it does not copy the vector. You must -- make sure that you never write again to the array. It is best to use -- unsafeFreeze only at the end of a block, that is run by -- runST. unsafeFreeze :: (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 () unsafeRead :: (Storable e) => Vector s e -> Int -> ST s e unsafeWrite :: (Storable e) => Vector s e -> Int -> e -> ST s () unsafeModify :: (Storable e) => Vector s e -> Int -> (e -> e) -> ST s () freeze :: (Storable e) => Vector s e -> ST s (Vector e) unsafeFreeze :: (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. -- -- Attention: This implementation is still almost 3 times slower than -- constructing a lazy storable vector using unfoldr in our Chorus speed -- test. module Data.StorableVector.Lazy.Builder data Builder a -- |
--   toLazyStorableVector (ChunkSize 7) $ foldMap put ['a'..'z']
--   
toLazyStorableVector :: Storable a => ChunkSize -> Builder a -> Vector a put :: Storable a => a -> Builder a -- | Set a laziness break. flush :: Storable a => Builder a instance Foreign.Storable.Storable a => Data.Semigroup.Semigroup (Data.StorableVector.Lazy.Builder.Builder a) instance Foreign.Storable.Storable a => GHC.Base.Monoid (Data.StorableVector.Lazy.Builder.Builder a)