on master help sign in
Change the signature of array getIndices
commitc8e46a7ebed3e926144fc87573fe791cacc2cec4 authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateWed 2 Feb 2022, 20:42 (5 years ago) parent185b43d
2 files changed+19−12
src/Streamly/Internal/Data/Array/Foreign.hs+6−3 src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+13−9
src/Streamly/Internal/Data/Array/Foreign.hs+6−3
@@ -150,6 +150,8 @@ import qualified Streamly.Internal.Data.Stream.StreamD as D
150150import qualified Streamly.Internal.Data.Unfold as Unfold
151151import qualified Streamly.Internal.Data.Ring.Foreign as RB
152152
153+
154+
153155-------------------------------------------------------------------------------
154156-- Construction
155157-------------------------------------------------------------------------------
@@ -458,10 +460,11 @@ getIndex arr i =
458460-- in Unfold.lmap f (getIndicesFromThenTo i (i - 1) 0)
459461-- @
460462--
461−-- /Unimplemented/
463+-- /Pre-release/
462464{-# INLINE getIndices #-}
463−getIndices :: Unfold m (Array a) Int -> Unfold m (Array a) a
464−getIndices = undefined
465+getIndices :: (MonadIO m, Storable a)
466+ => SerialT m Int -> Unfold m (Array a) a
467+getIndices st = Unfold.lmap A.unsafeThaw (MA.getIndices st)
465468
466469-- | Unfolds @(from, then, to, array)@ generating a finite stream whose first
467470-- element is the array value from the index @from@ and the successive elements
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+13−9
@@ -241,7 +241,8 @@ import GHC.Ptr (Ptr(..))
241241import Streamly.Internal.BaseCompat
242242import Streamly.Internal.Data.Fold.Type (Fold(..))
243243import Streamly.Internal.Data.Producer.Type (Producer (..))
244−import Streamly.Internal.Data.SVar.Type (adaptState)
244+import Streamly.Internal.Data.Stream.Serial (SerialT(..))
245+import Streamly.Internal.Data.SVar.Type (adaptState, defState)
245246import Streamly.Internal.Data.Unfold.Type (Unfold(..))
246247import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
247248import System.IO.Unsafe (unsafePerformIO)
@@ -1090,20 +1091,19 @@ data GetIndicesState contents start end st =
10901091-- bounds.
10911092--
10921093-- /Pre-release/
1093−{-# INLINE getIndices #-}
1094−getIndices :: (MonadIO m, Storable a) =>
1095− Unfold m (Array a) Int -> Unfold m (Array a) a
1096−getIndices (Unfold stepi injecti) = Unfold step inject
1094+{-# INLINE getIndicesD #-}
1095+getIndicesD :: (MonadIO m, Storable a) =>
1096+ D.Stream m Int -> Unfold m (Array a) a
1097+getIndicesD (D.Stream stepi sti) = Unfold step inject
10971098
10981099 where
10991100
1100− inject arr@(Array contents start (Ptr end) _) = do
1101− st <- injecti arr
1102− return $ GetIndicesState contents start (Ptr end) st
1101+ inject (Array contents start (Ptr end) _) =
1102+ return $ GetIndicesState contents start (Ptr end) sti
11031103
11041104 {-# INLINE_LATE step #-}
11051105 step (GetIndicesState contents start end st) = do
1106− r <- stepi st
1106+ r <- stepi defState st
11071107 case r of
11081108 D.Yield i s -> do
11091109 x <- liftIO $ getIndexPtr start end i
@@ -1113,6 +1113,10 @@ getIndices (Unfold stepi injecti) = Unfold step inject
11131113 liftIO $ touch contents
11141114 return D.Stop
11151115
1116+{-# INLINE getIndices #-}
1117+getIndices :: (MonadIO m, Storable a) => SerialT m Int -> Unfold m (Array a) a
1118+getIndices (SerialT stream) = getIndicesD $ D.fromStreamK stream
1119+
11161120-------------------------------------------------------------------------------
11171121-- Subarrays
11181122-------------------------------------------------------------------------------