on master help sign in
Add some notes on compactLE and compactLEFold
commitd48c9f7d51239d4675addb08d68078f1fcf2fb81 authorHarendra Kumar <harendra@composewell.com> dateSun 8 Aug 2021, 03:52 (5 years ago) parent9148b4d
2 files changed+19−6
src/Streamly/Internal/Data/Array/Stream/Foreign.hs+3 src/Streamly/Internal/Data/Array/Stream/Mut/Foreign.hs+16−6
src/Streamly/Internal/Data/Array/Stream/Foreign.hs+3
@@ -203,6 +203,9 @@ unlines sep (D.Stream step state) = D.Stream step' (OuterLoop state)
203203-- Compact
204204-------------------------------------------------------------------------------
205205
206+-- XXX These would not be needed once we implement compactLEFold, see
207+-- module Streamly.Internal.Data.Array.Stream.Mut.Foreign
208+--
206209{-# INLINE_NORMAL packArraysChunksOf #-}
207210packArraysChunksOf :: (MonadIO m, Storable a)
208211 => Int -> D.Stream m (Array a) -> D.Stream m (Array a)
src/Streamly/Internal/Data/Array/Stream/Mut/Foreign.hs+16−6
@@ -75,6 +75,8 @@ data SpliceState s arr
7575 | SpliceYielding arr (SpliceState s arr)
7676 | SpliceFinish
7777
78+-- XXX This can be removed once compactLEFold/compactLE are implemented.
79+--
7880-- | This mutates the first array (if it has space) to append values from the
7981-- second one. This would work for immutable arrays as well because an
8082-- immutable array never has space so a new array is allocated instead of
@@ -132,6 +134,9 @@ packArraysChunksOf n (D.Stream step state) =
132134
133135 step' _ (SpliceYielding arr next) = return $ D.Yield arr next
134136
137+-- XXX Remove this once compactLEFold is implemented
138+-- lpackArraysChunksOf = Fold.many compactLEFold
139+--
135140{-# INLINE_NORMAL lpackArraysChunksOf #-}
136141lpackArraysChunksOf :: (MonadIO m, Storable a)
137142 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
@@ -188,18 +193,19 @@ lpackArraysChunksOf n (Fold step1 initial1 extract1) =
188193 return $ first (Tuple' Nothing) res
189194 else return $ FL.Partial $ Tuple' (Just buf'') r1
190195
191−-- XXX replace by compactLE
196+-- XXX Same as compactLE, to be removed once that is implemented.
192197--
193198-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
194199-- maximum specified size in bytes.
195200--
196−-- @since 0.7.0
201+-- /Internal/
197202{-# INLINE compact #-}
198203compact :: (MonadIO m, Storable a)
199204 => Int -> SerialT m (Array a) -> SerialT m (Array a)
200205compact n xs = D.fromStreamD $ packArraysChunksOf n (D.toStreamD xs)
201206
202−-- XXX Replace the above functions by a compactLEFold
207+-- See lpackArraysChunksOf/packArraysChunksOf to implement this.
208+--
203209-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
204210-- maximum specified size. Note that if a single array is bigger than the
205211-- specified size we do not split it to fit. When we coalesce multiple arrays
@@ -212,12 +218,16 @@ compactLEFold :: -- (MonadIO m, Storable a) =>
212218 Int -> Fold m (Array a) (Array a)
213219compactLEFold = undefined
214220
221+-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
222+-- maximum specified size in bytes.
223+--
224+-- /Internal/
215225compactLE :: (MonadIO m {-, Storable a-}) =>
216226 Int -> SerialT m (Array a) -> SerialT m (Array a)
217227compactLE n xs = D.fromStreamD $ D.foldMany (compactLEFold n) (D.toStreamD xs)
218228
219−-- | Like 'compact' but generates arrays of exactly equal to the size specified
220−-- except for the last array in the stream which could be shorter.
229+-- | Like 'compactLE' but generates arrays of exactly equal to the size
230+-- specified except for the last array in the stream which could be shorter.
221231--
222232-- /Unimplemented/
223233{-# INLINE compactEQ #-}
@@ -226,7 +236,7 @@ compactEQ :: -- (MonadIO m, Storable a) =>
226236compactEQ _n _xs = undefined
227237 -- D.fromStreamD $ D.foldMany (compactEQFold n) (D.toStreamD xs)
228238
229−-- | Like 'compact' but generates arrays of size greater than or equal to the
239+-- | Like 'compactLE' but generates arrays of size greater than or equal to the
230240-- specified except for the last array in the stream which could be shorter.
231241--
232242-- /Unimplemented/