Skip to content

Commit

Permalink
Change the pinned prefix with a prime (') suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Dec 9, 2024
1 parent d2295fc commit aee485e
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 106 deletions.
2 changes: 1 addition & 1 deletion core/src/Streamly/Data/MutArray.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ import Control.Monad.IO.Class (MonadIO)
{-# DEPRECATED newPinned "Please use pinnedEmptyOf instead." #-}
{-# INLINE newPinned #-}
newPinned :: forall m a. (MonadIO m, Unbox a) => Int -> m (MutArray a)
newPinned = pinnedEmptyOf
newPinned = emptyOf'
76 changes: 44 additions & 32 deletions core/src/Streamly/Internal/Data/Array/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ module Streamly.Internal.Data.Array.Type
-- *** Stream Folds
, unsafeMakePure
, createOf
, pinnedCreateOf
, createOf'
, unsafeCreateOf
, unsafePinnedCreateOf
, unsafeCreateOf'
, create
, pinnedCreate
, create'
, createWith

-- *** From containers
, fromListN
, pinnedFromListN
, fromListN'
, fromList
, pinnedFromList
, fromList'
, fromListRevN
, fromListRev
, fromStreamN
Expand Down Expand Up @@ -112,7 +112,7 @@ module Streamly.Internal.Data.Array.Type
-- *** Chunk
-- | Group a stream into arrays.
, chunksOf
, pinnedChunksOf
, chunksOf'
, buildChunks
, chunksEndBy
, chunksEndBy'
Expand Down Expand Up @@ -164,6 +164,12 @@ module Streamly.Internal.Data.Array.Type
, lCompactGE
, lPinnedCompactGE
, compactGE
, pinnedCreateOf
, unsafePinnedCreateOf
, pinnedCreate
, pinnedFromListN
, pinnedFromList
, pinnedChunksOf
)
where

Expand Down Expand Up @@ -412,10 +418,11 @@ fromListN :: Unbox a => Int -> [a] -> Array a
fromListN n xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListN n xs

-- | Like 'fromListN' but creates a pinned array.
{-# INLINABLE pinnedFromListN #-}
pinnedFromListN :: Unbox a => Int -> [a] -> Array a
pinnedFromListN n xs =
unsafePerformIO $ unsafeFreeze <$> MA.pinnedFromListN n xs
{-# INLINABLE fromListN' #-}
pinnedFromListN, fromListN' :: Unbox a => Int -> [a] -> Array a
fromListN' n xs =
unsafePerformIO $ unsafeFreeze <$> MA.fromListN' n xs
RENAME_PRIME(pinnedFromListN,fromListN)

-- | Create an 'Array' from the first N elements of a list in reverse order.
-- The array is allocated to size N, if the list terminates before N elements
Expand All @@ -433,9 +440,10 @@ fromList :: Unbox a => [a] -> Array a
fromList xs = unsafePerformIO $ unsafeFreeze <$> MA.fromList xs

-- | Like 'fromList' but creates a pinned array.
{-# INLINE pinnedFromList #-}
pinnedFromList :: Unbox a => [a] -> Array a
pinnedFromList xs = unsafePerformIO $ unsafeFreeze <$> MA.pinnedFromList xs
{-# INLINE fromList' #-}
pinnedFromList, fromList' :: Unbox a => [a] -> Array a
fromList' xs = unsafePerformIO $ unsafeFreeze <$> MA.fromList' xs
RENAME_PRIME(pinnedFromList,fromList)

-- | Create an 'Array' from a list in reverse order. The list must be of finite
-- size.
Expand Down Expand Up @@ -513,10 +521,11 @@ chunksOf :: forall m a. (MonadIO m, Unbox a)
chunksOf n str = D.map unsafeFreeze $ MA.chunksOf n str

-- | Like 'chunksOf' but creates pinned arrays.
{-# INLINE_NORMAL pinnedChunksOf #-}
pinnedChunksOf :: forall m a. (MonadIO m, Unbox a)
{-# INLINE_NORMAL chunksOf' #-}
pinnedChunksOf, chunksOf' :: forall m a. (MonadIO m, Unbox a)
=> Int -> D.Stream m a -> D.Stream m (Array a)
pinnedChunksOf n str = D.map unsafeFreeze $ MA.pinnedChunksOf n str
chunksOf' n str = D.map unsafeFreeze $ MA.chunksOf' n str
RENAME_PRIME(pinnedChunksOf,chunksOf)

-- | Create arrays from the input stream using a predicate to find the end of
-- the chunk. When the predicate matches, the chunk ends, the matching element
Expand All @@ -536,7 +545,7 @@ chunksEndBy p = D.foldMany (Fold.takeEndBy p create)
{-# INLINE chunksEndBy' #-}
chunksEndBy' :: forall m a. (MonadIO m, Unbox a)
=> (a -> Bool) -> D.Stream m a -> D.Stream m (Array a)
chunksEndBy' p = D.foldMany (Fold.takeEndBy p pinnedCreate)
chunksEndBy' p = D.foldMany (Fold.takeEndBy p create')

-- | Create chunks using newline as the separator, including it.
{-# INLINE chunksEndByLn #-}
Expand Down Expand Up @@ -877,14 +886,15 @@ writeN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
writeN = createOf

-- | Like 'createOf' but creates a pinned array.
{-# INLINE_NORMAL pinnedCreateOf #-}
pinnedCreateOf :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
pinnedCreateOf = fmap unsafeFreeze . MA.pinnedCreateOf
{-# INLINE_NORMAL createOf' #-}
pinnedCreateOf, createOf' :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
createOf' = fmap unsafeFreeze . MA.createOf'
RENAME_PRIME(pinnedCreateOf,createOf)

{-# DEPRECATED pinnedWriteN "Please use pinnedCreateOf instead." #-}
{-# DEPRECATED pinnedWriteN "Please use createOf' instead." #-}
{-# INLINE pinnedWriteN #-}
pinnedWriteN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
pinnedWriteN = pinnedCreateOf
pinnedWriteN = createOf'

-- | @pinnedWriteNAligned alignment n@ folds a maximum of @n@ elements from the input
-- stream to an 'Array' aligned to the given size.
Expand Down Expand Up @@ -914,16 +924,17 @@ writeNUnsafe :: forall m a. (MonadIO m, Unbox a)
=> Int -> Fold m a (Array a)
writeNUnsafe = unsafeCreateOf

{-# INLINE_NORMAL unsafePinnedCreateOf #-}
unsafePinnedCreateOf :: forall m a. (MonadIO m, Unbox a)
{-# INLINE_NORMAL unsafeCreateOf' #-}
unsafePinnedCreateOf, unsafeCreateOf' :: forall m a. (MonadIO m, Unbox a)
=> Int -> Fold m a (Array a)
unsafePinnedCreateOf n = unsafeFreeze <$> MA.unsafePinnedCreateOf n
unsafeCreateOf' n = unsafeFreeze <$> MA.unsafeCreateOf' n
RENAME_PRIME(unsafePinnedCreateOf,unsafeCreateOf)

{-# DEPRECATED pinnedWriteNUnsafe "Please use unsafePinnedCreateOf instead." #-}
{-# DEPRECATED pinnedWriteNUnsafe "Please use unsafeCreateOf' instead." #-}
{-# INLINE pinnedWriteNUnsafe #-}
pinnedWriteNUnsafe :: forall m a. (MonadIO m, Unbox a)
=> Int -> Fold m a (Array a)
pinnedWriteNUnsafe = unsafePinnedCreateOf
pinnedWriteNUnsafe = unsafeCreateOf'

-- | A version of "create" that let's you pass in the initial capacity of the
-- array in terms of the number of elements.
Expand Down Expand Up @@ -960,14 +971,15 @@ write :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
write = create

-- | Like 'create' but creates a pinned array.
{-# INLINE pinnedCreate #-}
pinnedCreate :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
pinnedCreate = fmap unsafeFreeze MA.pinnedCreate
{-# INLINE create' #-}
pinnedCreate, create' :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
create' = fmap unsafeFreeze MA.create'
RENAME_PRIME(pinnedCreate,create)

{-# DEPRECATED pinnedWrite "Please use pinnedCreate instead." #-}
{-# DEPRECATED pinnedWrite "Please use create' instead." #-}
{-# INLINE pinnedWrite #-}
pinnedWrite :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
pinnedWrite = pinnedCreate
pinnedWrite = create'

-- | Fold "step" has a dependency on "initial", and each step is dependent on
-- the previous invocation of step due to state passing, finally extract
Expand Down
2 changes: 1 addition & 1 deletion core/src/Streamly/Internal/Data/Fold/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ bottomBy cmp n = Fold step initial extract extract
where

initial = do
arr <- MA.pinnedEmptyOf n
arr <- MA.emptyOf' n
if n <= 0
then return $ Done arr
else return $ Partial (arr, 0)
Expand Down
Loading

0 comments on commit aee485e

Please sign in to comment.