on master help sign in
Add some notes on compactLE and compactLEFold
d48c9f7Harendra Kumar
src/Streamly/Internal/Data/Array/Stream/Foreign.hs+3
@@ -203,6 +203,9 @@ unlines sep (D.Stream step state) = D.Stream step' (OuterLoop state)
203-- Compact
203-- Compact
204-------------------------------------------------------------------------------
204-------------------------------------------------------------------------------
205
205
206+-- XXX These would not be needed once we implement compactLEFold, see
207+-- module Streamly.Internal.Data.Array.Stream.Mut.Foreign
208+--
206{-# INLINE_NORMAL packArraysChunksOf #-}
209{-# INLINE_NORMAL packArraysChunksOf #-}
207packArraysChunksOf :: (MonadIO m, Storable a)
210packArraysChunksOf :: (MonadIO m, Storable a)
208 => Int -> D.Stream m (Array a) -> D.Stream m (Array a)
211 => 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
75 | SpliceYielding arr (SpliceState s arr)
75 | SpliceYielding arr (SpliceState s arr)
76 | SpliceFinish
76 | SpliceFinish
77
77
78+-- XXX This can be removed once compactLEFold/compactLE are implemented.
79+--
78-- | This mutates the first array (if it has space) to append values from the
80-- | This mutates the first array (if it has space) to append values from the
79-- second one. This would work for immutable arrays as well because an
81-- second one. This would work for immutable arrays as well because an
80-- immutable array never has space so a new array is allocated instead of
82-- immutable array never has space so a new array is allocated instead of
@@ -132,6 +134,9 @@ packArraysChunksOf n (D.Stream step state) =
132
134
133 step' _ (SpliceYielding arr next) = return $ D.Yield arr next
135 step' _ (SpliceYielding arr next) = return $ D.Yield arr next
134
136
137+-- XXX Remove this once compactLEFold is implemented
138+-- lpackArraysChunksOf = Fold.many compactLEFold
139+--
135{-# INLINE_NORMAL lpackArraysChunksOf #-}
140{-# INLINE_NORMAL lpackArraysChunksOf #-}
136lpackArraysChunksOf :: (MonadIO m, Storable a)
141lpackArraysChunksOf :: (MonadIO m, Storable a)
137 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
142 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
@@ -188,18 +193,19 @@ lpackArraysChunksOf n (Fold step1 initial1 extract1) =
188 return $ first (Tuple' Nothing) res
193 return $ first (Tuple' Nothing) res
189 else return $ FL.Partial $ Tuple' (Just buf'') r1
194 else return $ FL.Partial $ Tuple' (Just buf'') r1
190
195
191−-- XXX replace by compactLE
196+-- XXX Same as compactLE, to be removed once that is implemented.
192--
197--
193-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
198-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
194-- maximum specified size in bytes.
199-- maximum specified size in bytes.
195--
200--
196−-- @since 0.7.0
201+-- /Internal/
197{-# INLINE compact #-}
202{-# INLINE compact #-}
198compact :: (MonadIO m, Storable a)
203compact :: (MonadIO m, Storable a)
199 => Int -> SerialT m (Array a) -> SerialT m (Array a)
204 => Int -> SerialT m (Array a) -> SerialT m (Array a)
200compact n xs = D.fromStreamD $ packArraysChunksOf n (D.toStreamD xs)
205compact n xs = D.fromStreamD $ packArraysChunksOf n (D.toStreamD xs)
201
206
202−-- XXX Replace the above functions by a compactLEFold
207+-- See lpackArraysChunksOf/packArraysChunksOf to implement this.
208+--
203-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
209-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
204-- maximum specified size. Note that if a single array is bigger than the
210-- maximum specified size. Note that if a single array is bigger than the
205-- specified size we do not split it to fit. When we coalesce multiple arrays
211-- specified size we do not split it to fit. When we coalesce multiple arrays
@@ -212,12 +218,16 @@ compactLEFold :: -- (MonadIO m, Storable a) =>
212 Int -> Fold m (Array a) (Array a)
218 Int -> Fold m (Array a) (Array a)
213compactLEFold = undefined
219compactLEFold = undefined
214
220
221+-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
222+-- maximum specified size in bytes.
223+--
224+-- /Internal/
215compactLE :: (MonadIO m {-, Storable a-}) =>
225compactLE :: (MonadIO m {-, Storable a-}) =>
216 Int -> SerialT m (Array a) -> SerialT m (Array a)
226 Int -> SerialT m (Array a) -> SerialT m (Array a)
217compactLE n xs = D.fromStreamD $ D.foldMany (compactLEFold n) (D.toStreamD xs)
227compactLE n xs = D.fromStreamD $ D.foldMany (compactLEFold n) (D.toStreamD xs)
218
228
219−-- | Like 'compact' but generates arrays of exactly equal to the size specified
229+-- | Like 'compactLE' but generates arrays of exactly equal to the size
220−-- except for the last array in the stream which could be shorter.
230+-- specified except for the last array in the stream which could be shorter.
221--
231--
222-- /Unimplemented/
232-- /Unimplemented/
223{-# INLINE compactEQ #-}
233{-# INLINE compactEQ #-}
@@ -226,7 +236,7 @@ compactEQ :: -- (MonadIO m, Storable a) =>
226compactEQ _n _xs = undefined
236compactEQ _n _xs = undefined
227 -- D.fromStreamD $ D.foldMany (compactEQFold n) (D.toStreamD xs)
237 -- D.fromStreamD $ D.foldMany (compactEQFold n) (D.toStreamD xs)
228
238
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
230-- specified except for the last array in the stream which could be shorter.
240-- specified except for the last array in the stream which could be shorter.
231--
241--
232-- /Unimplemented/
242-- /Unimplemented/