@@ -2,7 +2,6 @@
3-- Module : Streamly.Internal.Data.Array
3-- Module : Streamly.Internal.Data.Array
4-- Copyright : (c) 2019 Composewell Technologies
4-- Copyright : (c) 2019 Composewell Technologies
6-- License : BSD3
5-- License : BSD3
7-- Maintainer : streamly@composewell.com
6-- Maintainer : streamly@composewell.com
8-- Stability : experimental
7-- Stability : experimental
@@ -27,21 +26,23 @@ module Streamly.Internal.Data.Array
28 , getIndex
27 , getIndex
29 , getIndexRev
28 , getIndexRev
30− , last -- XXX getIndexLast?
29+ , last -- XXX getLastIndex?
32− , getIndicesFromThenTo
33 -- , getIndicesFrom -- read from a given position to the end of file
30 -- , getIndicesFrom -- read from a given position to the end of file
34 -- , getIndicesUpto -- read from beginning up to the given position
31 -- , getIndicesUpto -- read from beginning up to the given position
35 -- , getIndicesFromTo
32 -- , getIndicesFromTo
36 -- , getIndicesFromRev -- read from a given position to the beginning of file
33 -- , getIndicesFromRev -- read from a given position to the beginning of file
37 -- , getIndicesUptoRev -- read from end to the given position in file
34 -- , getIndicesUptoRev -- read from end to the given position in file
36+ , indexReaderFromThenTo
42 -- * Search
41 -- * Search
43 , binarySearch
42 , binarySearch
44− , findIndicesOf -- see splitOn, rename to indicesOf
43+ , findIndicesOf
45+ , indexFinder -- see splitOn
45 -- , findIndexOf
46 -- , findIndexOf
@@ -74,6 +75,7 @@ module Streamly.Internal.Data.Array
74 -- * Deprecated
75 -- * Deprecated
75 , genSlicesFromLen
76 , genSlicesFromLen
76 , getSlicesFromLen
77 , getSlicesFromLen
@@ -226,19 +228,26 @@ binarySearch = undefined
226-- compared to streams by using SIMD instructions.
228-- compared to streams by using SIMD instructions.
227-- We can also return a bit array instead.
229-- We can also return a bit array instead.
229-- | Perform a linear search to find all the indices where a given element is
233-- | Perform a linear search to find all the indices where a given element is
230-- present in an array.
234-- present in an array.
232-- /Unimplemented/
236-- /Unimplemented/
233−findIndicesOf :: (a -> Bool) -> Unfold Identity (Array a) Int
237+indexFinder :: (a -> Bool) -> Unfold Identity (Array a) Int
234−findIndicesOf = undefined
238+indexFinder = undefined
242+findIndicesOf :: (a -> Bool) -> Array a -> Stream Identity Int
243+findIndicesOf p = Stream.unfold (indexFinder p)
237findIndexOf :: (a -> Bool) -> Array a -> Maybe Int
246findIndexOf :: (a -> Bool) -> Array a -> Maybe Int
238−findIndexOf p = Unfold.fold Fold.one . Stream.unfold (findIndicesOf p)
247+findIndexOf p = Unfold.fold Fold.one . Stream.unfold (indexFinder p)
240find :: (a -> Bool) -> Array a -> Bool
249find :: (a -> Bool) -> Array a -> Bool
241−find = Unfold.fold Fold.null . Stream.unfold (findIndicesOf p)
250+find = Unfold.fold Fold.null . Stream.unfold (indexFinder p)
244-------------------------------------------------------------------------------
253-------------------------------------------------------------------------------
@@ -346,20 +355,25 @@ getIndex i arr =
348-- let u = lmap (\arr -> (0, length arr - 1)) Unfold.enumerateFromTo
357-- let u = lmap (\arr -> (0, length arr - 1)) Unfold.enumerateFromTo
349−-- in Unfold.lmap f (getIndices arr)
358+-- in Unfold.lmap f (indexReader arr)
351-- readRev =
360-- readRev =
352-- let i = length arr - 1
361-- let i = length arr - 1
353−-- in Unfold.lmap f (getIndicesFromThenTo i (i - 1) 0)
362+-- in Unfold.lmap f (indexReaderFromThenTo i (i - 1) 0)
356-- /Pre-release/
365-- /Pre-release/
357−{-# INLINE getIndices #-}
366+{-# INLINE indexReader #-}
358−getIndices :: (Monad m, Unbox a) => Stream m Int -> Unfold m (Array a) a
367+indexReader :: (Monad m, Unbox a) => Stream m Int -> Unfold m (Array a) a
359−getIndices m =
368+indexReader m =
360− let unf = MA.getIndicesWith (return . unsafeInlineIO) m
369+ let unf = MA.indexReaderWith (return . unsafeInlineIO) m
361 in Unfold.lmap A.unsafeThaw unf
370 in Unfold.lmap A.unsafeThaw unf
372+-- XXX DO NOT REMOVE, change the signature to use Stream instead of unfold
373+{-# DEPRECATED getIndices "Please use getIndices instead." #-}
374+getIndices :: (Monad m, Unbox a) => Stream m Int -> Unfold m (Array a) a
375+getIndices = indexReader
363-- | Unfolds @(from, then, to, array)@ generating a finite stream whose first
377-- | Unfolds @(from, then, to, array)@ generating a finite stream whose first
364-- element is the array value from the index @from@ and the successive elements
378-- element is the array value from the index @from@ and the successive elements
365-- are from the indices in increments of @then@ up to @to@. Index enumeration
379-- are from the indices in increments of @then@ up to @to@. Index enumeration
@@ -374,9 +388,9 @@ getIndices m =
376-- /Unimplemented/
390-- /Unimplemented/
377−{-# INLINE getIndicesFromThenTo #-}
391+{-# INLINE indexReaderFromThenTo #-}
378−getIndicesFromThenTo :: Unfold m (Int, Int, Int, Array a) a
392+indexReaderFromThenTo :: Unfold m (Int, Int, Int, Array a) a
379−getIndicesFromThenTo = undefined
393+indexReaderFromThenTo = undefined
381-------------------------------------------------------------------------------
395-------------------------------------------------------------------------------
382-- Transform via stream operations
396-- Transform via stream operations