on master help sign in
Create array with the new element inserted
889be18Ranjeet Kumar Ranjan
core/src/Streamly/Internal/Data/Ring/Foreign.hs+7−3
@@ -514,7 +514,11 @@ unsafeFoldRingNM count rh f z rb@Ring {..} =
514
514
515data Tuple4' a b c d = Tuple4' !a !b !c !d deriving Show
515data Tuple4' a b c d = Tuple4' !a !b !c !d deriving Show
516
516
517+-- | Like slidingWindow but also provides the entire ring contents as an Array.
518+-- The array reflects the state of the ring after inserting the incoming
519+-- element.
520+--
517−-- | IMPORTANT NOTE: The ring is mutable, therefore, the result of @(m (Array
521+-- IMPORTANT NOTE: The ring is mutable, therefore, the result of @(m (Array
518-- a))@ action depends on when it is executed. It does not capture the sanpshot
522-- a))@ action depends on when it is executed. It does not capture the sanpshot
519-- of the ring at a particular time.
523-- of the ring at a particular time.
520{-# INLINE slidingWindowWith #-}
524{-# INLINE slidingWindowWith #-}
@@ -544,7 +548,7 @@ slidingWindowWith n (Fold step1 initial1 extract1) = Fold step initial extract
544 | i < n = do
548 | i < n = do
545 rh1 <- liftIO $ unsafeInsert rb rh a
549 rh1 <- liftIO $ unsafeInsert rb rh a
546 liftIO $ touchForeignPtr (ringStart rb)
550 liftIO $ touchForeignPtr (ringStart rb)
547− r <- step1 st ((a, Nothing), toArray unsafeFoldRingM rb rh)
551+ r <- step1 st ((a, Nothing), toArray unsafeFoldRingM rb rh1)
548 return $
552 return $
549 case r of
553 case r of
550 Partial s -> Partial $ Tuple4' rb rh1 (i + 1) s
554 Partial s -> Partial $ Tuple4' rb rh1 (i + 1) s
@@ -553,7 +557,7 @@ slidingWindowWith n (Fold step1 initial1 extract1) = Fold step initial extract
553 old <- liftIO $ peek rh
557 old <- liftIO $ peek rh
554 rh1 <- liftIO $ unsafeInsert rb rh a
558 rh1 <- liftIO $ unsafeInsert rb rh a
555 liftIO $ touchForeignPtr (ringStart rb)
559 liftIO $ touchForeignPtr (ringStart rb)
556− r <- step1 st ((a, Just old), toArray unsafeFoldRingFullM rb rh)
560+ r <- step1 st ((a, Just old), toArray unsafeFoldRingFullM rb rh1)
557 return $
561 return $
558 case r of
562 case r of
559 Partial s -> Partial $ Tuple4' rb rh1 (i + 1) s
563 Partial s -> Partial $ Tuple4' rb rh1 (i + 1) s