@@ -223,7 +223,7 @@ import Foreign.C.Types (CSize(..), CInt(..))
223import Foreign.Ptr (plusPtr, minusPtr, nullPtr)
223import Foreign.Ptr (plusPtr, minusPtr, nullPtr)
224import Streamly.Internal.Data.Unboxed
224import Streamly.Internal.Data.Unboxed
225 ( MutableByteArray(..)
225 ( MutableByteArray(..)
226− , Unboxed
226+ , Unbox
227 , alignment
227 , alignment
228 , castContents
228 , castContents
229 , getMutableByteArray#
229 , getMutableByteArray#
@@ -286,7 +286,7 @@ foreign import ccall unsafe "string.h memcmp" c_memcmp
286-- how many elements of that type will completely fit in those bytes.
286-- how many elements of that type will completely fit in those bytes.
288{-# INLINE bytesToElemCount #-}
288{-# INLINE bytesToElemCount #-}
289−bytesToElemCount :: forall a. Unboxed a => a -> Int -> Int
289+bytesToElemCount :: forall a. Unbox a => a -> Int -> Int
290bytesToElemCount _ n = n `div` SIZE_OF(a)
290bytesToElemCount _ n = n `div` SIZE_OF(a)
292-- XXX we are converting Int to CSize
292-- XXX we are converting Int to CSize
@@ -333,7 +333,7 @@ memcmp p1 p2 len = do
334data Array a =
334data Array a =
335#ifdef DEVBUILD
335#ifdef DEVBUILD
336− Unboxed a =>
336+ Unbox a =>
338 -- The array is a range into arrContents. arrContents may be a superset of
338 -- The array is a range into arrContents. arrContents may be a superset of
339 -- the slice represented by the array. All offsets are in bytes.
339 -- the slice represented by the array. All offsets are in bytes.
@@ -389,7 +389,7 @@ unpin arr@Array{..} = do
390-- /Pre-release/
390-- /Pre-release/
391{-# INLINE newArrayWith #-}
391{-# INLINE newArrayWith #-}
392−newArrayWith :: forall m a. (MonadIO m, Unboxed a)
392+newArrayWith :: forall m a. (MonadIO m, Unbox a)
393 => (Int -> Int -> m (MutableByteArray a)) -> Int -> Int -> m (Array a)
393 => (Int -> Int -> m (MutableByteArray a)) -> Int -> Int -> m (Array a)
394newArrayWith alloc alignSize count = do
394newArrayWith alloc alignSize count = do
395 let size = max (count * SIZE_OF(a)) 0
395 let size = max (count * SIZE_OF(a)) 0
@@ -403,7 +403,7 @@ newArrayWith alloc alignSize count = do
405#ifdef DEVBUILD
405#ifdef DEVBUILD
406− Unboxed a =>
406+ Unbox a =>
409nil = Array Unboxed.nil 0 0 0
409nil = Array Unboxed.nil 0 0 0
@@ -415,7 +415,7 @@ nil = Array Unboxed.nil 0 0 0
416-- /Pre-release/
416-- /Pre-release/
417{-# INLINE newPinnedBytes #-}
417{-# INLINE newPinnedBytes #-}
418−newPinnedBytes :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
418+newPinnedBytes :: forall m a. (MonadIO m, Unbox a) => Int -> m (Array a)
419newPinnedBytes bytes = do
419newPinnedBytes bytes = do
420 contents <-
420 contents <-
@@ -432,7 +432,7 @@ newPinnedBytes bytes = do
433-- /Internal/
433-- /Internal/
434{-# INLINE newAlignedPinned #-}
434{-# INLINE newAlignedPinned #-}
435−newAlignedPinned :: (MonadIO m, Unboxed a) => Int -> Int -> m (Array a)
435+newAlignedPinned :: (MonadIO m, Unbox a) => Int -> Int -> m (Array a)
436newAlignedPinned =
436newAlignedPinned =
437 newArrayWith (\s a -> liftIO $ Unboxed.newAlignedPinnedBytes s a)
437 newArrayWith (\s a -> liftIO $ Unboxed.newAlignedPinnedBytes s a)
@@ -443,14 +443,14 @@ newAlignedPinned =
443-- instance of the type.
443-- instance of the type.
445{-# INLINE newPinned #-}
445{-# INLINE newPinned #-}
446−newPinned :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
446+newPinned :: forall m a. (MonadIO m, Unbox a) => Int -> m (Array a)
447newPinned = newAlignedPinned (alignment (undefined :: a))
447newPinned = newAlignedPinned (alignment (undefined :: a))
449-- | Allocates an empty unpinned array that can hold 'count' items. The memory
449-- | Allocates an empty unpinned array that can hold 'count' items. The memory
450-- of the array is uninitialized.
450-- of the array is uninitialized.
452{-# INLINE new #-}
452{-# INLINE new #-}
453−new :: (MonadIO m, Unboxed a) => Int -> m (Array a)
453+new :: (MonadIO m, Unbox a) => Int -> m (Array a)
455 newArrayWith
455 newArrayWith
456 (\s _ -> liftIO $ Unboxed.newUnpinnedBytes s)
456 (\s _ -> liftIO $ Unboxed.newUnpinnedBytes s)
@@ -462,7 +462,7 @@ new =
462-- /Internal/
462-- /Internal/
463{-# INLINE withNewArrayUnsafe #-}
463{-# INLINE withNewArrayUnsafe #-}
464withNewArrayUnsafe ::
464withNewArrayUnsafe ::
465− (MonadIO m, Unboxed a) => Int -> (Ptr a -> m ()) -> m (Array a)
465+ (MonadIO m, Unbox a) => Int -> (Ptr a -> m ()) -> m (Array a)
466withNewArrayUnsafe count f = do
466withNewArrayUnsafe count f = do
467 arr <- newPinned count
467 arr <- newPinned count
468 asPtrUnsafe arr
468 asPtrUnsafe arr
@@ -477,7 +477,7 @@ withNewArrayUnsafe count f = do
478-- /Pre-release/
478-- /Pre-release/
479{-# INLINE putIndexUnsafe #-}
479{-# INLINE putIndexUnsafe #-}
480−putIndexUnsafe :: forall m a. (MonadIO m, Unboxed a)
480+putIndexUnsafe :: forall m a. (MonadIO m, Unbox a)
481 => Int -> a -> Array a -> m ()
481 => Int -> a -> Array a -> m ()
482putIndexUnsafe i x Array{..} = do
482putIndexUnsafe i x Array{..} = do
483 let index = INDEX_OF(arrStart, i, a)
483 let index = INDEX_OF(arrStart, i, a)
@@ -496,7 +496,7 @@ invalidIndex label i =
496-- >>> putIndex ix val arr = Stream.fold (f arr) (Stream.fromPure (ix, val))
496-- >>> putIndex ix val arr = Stream.fold (f arr) (Stream.fromPure (ix, val))
498{-# INLINE putIndex #-}
498{-# INLINE putIndex #-}
499−putIndex :: forall m a. (MonadIO m, Unboxed a) => Int -> a -> Array a -> m ()
499+putIndex :: forall m a. (MonadIO m, Unbox a) => Int -> a -> Array a -> m ()
500putIndex i x Array{..} = do
500putIndex i x Array{..} = do
501 let index = INDEX_OF(arrStart,i,a)
501 let index = INDEX_OF(arrStart,i,a)
502 if i >= 0 && INDEX_VALID(index,arrEnd,a)
502 if i >= 0 && INDEX_VALID(index,arrEnd,a)
@@ -508,7 +508,7 @@ putIndex i x Array{..} = do
509-- /Pre-release/
509-- /Pre-release/
510{-# INLINE putIndices #-}
510{-# INLINE putIndices #-}
511−putIndices :: forall m a. (MonadIO m, Unboxed a)
511+putIndices :: forall m a. (MonadIO m, Unbox a)
512 => Array a -> Fold m (Int, a) ()
512 => Array a -> Fold m (Int, a) ()
513putIndices arr = FL.foldlM' step (return ())
513putIndices arr = FL.foldlM' step (return ())
@@ -519,7 +519,7 @@ putIndices arr = FL.foldlM' step (return ())
519-- | Modify a given index of an array using a modifier function.
519-- | Modify a given index of an array using a modifier function.
521-- /Pre-release/
521-- /Pre-release/
522−modifyIndexUnsafe :: forall m a b. (MonadIO m, Unboxed a) =>
522+modifyIndexUnsafe :: forall m a b. (MonadIO m, Unbox a) =>
523 Int -> (a -> (a, b)) -> Array a -> m b
523 Int -> (a -> (a, b)) -> Array a -> m b
524modifyIndexUnsafe i f Array{..} = liftIO $ do
524modifyIndexUnsafe i f Array{..} = liftIO $ do
525 let index = INDEX_OF(arrStart,i,a)
525 let index = INDEX_OF(arrStart,i,a)
@@ -532,7 +532,7 @@ modifyIndexUnsafe i f Array{..} = liftIO $ do
532-- | Modify a given index of an array using a modifier function.
532-- | Modify a given index of an array using a modifier function.
534-- /Pre-release/
534-- /Pre-release/
535−modifyIndex :: forall m a b. (MonadIO m, Unboxed a) =>
535+modifyIndex :: forall m a b. (MonadIO m, Unbox a) =>
536 Int -> (a -> (a, b)) -> Array a -> m b
536 Int -> (a -> (a, b)) -> Array a -> m b
537modifyIndex i f Array{..} = do
537modifyIndex i f Array{..} = do
538 let index = INDEX_OF(arrStart,i,a)
538 let index = INDEX_OF(arrStart,i,a)
@@ -549,7 +549,7 @@ modifyIndex i f Array{..} = do
550-- /Pre-release/
550-- /Pre-release/
551{-# INLINE modifyIndices #-}
551{-# INLINE modifyIndices #-}
552−modifyIndices :: forall m a . (MonadIO m, Unboxed a)
552+modifyIndices :: forall m a . (MonadIO m, Unbox a)
553 => (Int -> a -> a) -> Array a -> Fold m Int ()
553 => (Int -> a -> a) -> Array a -> Fold m Int ()
554modifyIndices f arr = FL.foldlM' step initial
554modifyIndices f arr = FL.foldlM' step initial
@@ -564,7 +564,7 @@ modifyIndices f arr = FL.foldlM' step initial
564-- | Modify each element of an array using the supplied modifier function.
564-- | Modify each element of an array using the supplied modifier function.
566-- /Pre-release/
566-- /Pre-release/
567−modify :: forall m a. (MonadIO m, Unboxed a)
567+modify :: forall m a. (MonadIO m, Unbox a)
568 => (a -> a) -> Array a -> m ()
568 => (a -> a) -> Array a -> m ()
569modify f Array{..} = liftIO $
569modify f Array{..} = liftIO $
570 go arrStart
570 go arrStart
@@ -578,7 +578,7 @@ modify f Array{..} = liftIO $
578 go (INDEX_NEXT(i,a))
578 go (INDEX_NEXT(i,a))
580{-# INLINE swapArrayByteIndices #-}
580{-# INLINE swapArrayByteIndices #-}
581−swapArrayByteIndices :: Unboxed a => MutableByteArray a -> Int -> Int -> IO ()
581+swapArrayByteIndices :: Unbox a => MutableByteArray a -> Int -> Int -> IO ()
582swapArrayByteIndices arrContents i1 i2 = do
582swapArrayByteIndices arrContents i1 i2 = do
583 r1 <- peekWith arrContents i1
583 r1 <- peekWith arrContents i1
584 r2 <- peekWith arrContents i2
584 r2 <- peekWith arrContents i2
@@ -591,7 +591,7 @@ swapArrayByteIndices arrContents i1 i2 = do
592-- /Pre-release/
592-- /Pre-release/
593{-# INLINE unsafeSwapIndices #-}
593{-# INLINE unsafeSwapIndices #-}
594−unsafeSwapIndices :: forall m a. (MonadIO m, Unboxed a)
594+unsafeSwapIndices :: forall m a. (MonadIO m, Unbox a)
595 => Int -> Int -> Array a -> m ()
595 => Int -> Int -> Array a -> m ()
596unsafeSwapIndices i1 i2 Array{..} = liftIO $ do
596unsafeSwapIndices i1 i2 Array{..} = liftIO $ do
597 let t1 = INDEX_OF(arrStart,i1,a)
597 let t1 = INDEX_OF(arrStart,i1,a)
@@ -601,7 +601,7 @@ unsafeSwapIndices i1 i2 Array{..} = liftIO $ do
601-- | Swap the elements at two indices.
601-- | Swap the elements at two indices.
603-- /Pre-release/
603-- /Pre-release/
604−swapIndices :: forall m a. (MonadIO m, Unboxed a)
604+swapIndices :: forall m a. (MonadIO m, Unbox a)
605 => Int -> Int -> Array a -> m ()
605 => Int -> Int -> Array a -> m ()
606swapIndices i1 i2 Array{..} = liftIO $ do
606swapIndices i1 i2 Array{..} = liftIO $ do
607 let t1 = INDEX_OF(arrStart,i1,a)
607 let t1 = INDEX_OF(arrStart,i1,a)
@@ -672,7 +672,7 @@ roundUpToPower2 n =
672-- case it returns one element's size.
672-- case it returns one element's size.
674{-# INLINE allocBytesToBytes #-}
674{-# INLINE allocBytesToBytes #-}
675−allocBytesToBytes :: forall a. Unboxed a => a -> Int -> Int
675+allocBytesToBytes :: forall a. Unbox a => a -> Int -> Int
676allocBytesToBytes _ n = max (arrayPayloadSize n) (SIZE_OF(a))
676allocBytesToBytes _ n = max (arrayPayloadSize n) (SIZE_OF(a))
678-- | Given an 'Unboxed' type (unused first arg) and real allocation size
678-- | Given an 'Unboxed' type (unused first arg) and real allocation size
@@ -680,7 +680,7 @@ allocBytesToBytes _ n = max (arrayPayloadSize n) (SIZE_OF(a))
680-- fit in it, returns at least 1.
680-- fit in it, returns at least 1.
682{-# INLINE allocBytesToElemCount #-}
682{-# INLINE allocBytesToElemCount #-}
683−allocBytesToElemCount :: Unboxed a => a -> Int -> Int
683+allocBytesToElemCount :: Unbox a => a -> Int -> Int
684allocBytesToElemCount x bytes =
684allocBytesToElemCount x bytes =
685 let n = bytesToElemCount x (allocBytesToBytes x bytes)
685 let n = bytesToElemCount x (allocBytesToBytes x bytes)
686 in assert (n >= 1) n
686 in assert (n >= 1) n
@@ -745,14 +745,14 @@ reallocAligned elemSize alignSize newCapacityInBytes Array{..} = do
745-- 'largeObjectThreshold' then it is rounded up to the block size (4K).
745-- 'largeObjectThreshold' then it is rounded up to the block size (4K).
747{-# INLINABLE realloc #-}
747{-# INLINABLE realloc #-}
748−realloc :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m (Array a)
748+realloc :: forall m a. (MonadIO m, Unbox a) => Int -> Array a -> m (Array a)
749realloc bytes arr =
749realloc bytes arr =
750 liftIO $ reallocAligned (SIZE_OF(a)) (alignment (undefined :: a)) bytes arr
750 liftIO $ reallocAligned (SIZE_OF(a)) (alignment (undefined :: a)) bytes arr
752-- | @reallocWith label capSizer minIncrBytes array@. The label is used
752-- | @reallocWith label capSizer minIncrBytes array@. The label is used
753-- in error messages and the capSizer is used to determine the capacity of the
753-- in error messages and the capSizer is used to determine the capacity of the
754-- new array in bytes given the current byte length of the array.
754-- new array in bytes given the current byte length of the array.
755−reallocWith :: forall m a. (MonadIO m , Unboxed a) =>
755+reallocWith :: forall m a. (MonadIO m , Unbox a) =>
757 -> (Int -> Int)
757 -> (Int -> Int)
@@ -786,7 +786,7 @@ reallocWith label capSizer minIncrBytes arr = do
787-- /Pre-release/
787-- /Pre-release/
788{-# INLINE resize #-}
788{-# INLINE resize #-}
789−resize :: forall m a. (MonadIO m, Unboxed a) =>
789+resize :: forall m a. (MonadIO m, Unbox a) =>
790 Int -> Array a -> m (Array a)
790 Int -> Array a -> m (Array a)
791resize nElems arr@Array{..} = do
791resize nElems arr@Array{..} = do
792 let req = SIZE_OF(a) * nElems
792 let req = SIZE_OF(a) * nElems
@@ -800,7 +800,7 @@ resize nElems arr@Array{..} = do
801-- /Pre-release/
801-- /Pre-release/
802{-# INLINE resizeExp #-}
802{-# INLINE resizeExp #-}
803−resizeExp :: forall m a. (MonadIO m, Unboxed a) =>
803+resizeExp :: forall m a. (MonadIO m, Unbox a) =>
804 Int -> Array a -> m (Array a)
804 Int -> Array a -> m (Array a)
805resizeExp nElems arr@Array{..} = do
805resizeExp nElems arr@Array{..} = do
806 let req = roundUpLargeArray (SIZE_OF(a) * nElems)
806 let req = roundUpLargeArray (SIZE_OF(a) * nElems)
@@ -822,7 +822,7 @@ resizeExp nElems arr@Array{..} = do
823-- /Pre-release/
823-- /Pre-release/
824{-# INLINE rightSize #-}
824{-# INLINE rightSize #-}
825−rightSize :: forall m a. (MonadIO m, Unboxed a) => Array a -> m (Array a)
825+rightSize :: forall m a. (MonadIO m, Unbox a) => Array a -> m (Array a)
826rightSize arr@Array{..} = do
826rightSize arr@Array{..} = do
827 assert (arrEnd <= arrBound) (return ())
827 assert (arrEnd <= arrBound) (return ())
828 let start = arrStart
828 let start = arrStart
@@ -854,7 +854,7 @@ rightSize arr@Array{..} = do
855-- /Internal/
855-- /Internal/
856{-# INLINE snocNewEnd #-}
856{-# INLINE snocNewEnd #-}
857−snocNewEnd :: (MonadIO m, Unboxed a) => Int -> Array a -> a -> m (Array a)
857+snocNewEnd :: (MonadIO m, Unbox a) => Int -> Array a -> a -> m (Array a)
858snocNewEnd newEnd arr@Array{..} x = liftIO $ do
858snocNewEnd newEnd arr@Array{..} x = liftIO $ do
859 assert (newEnd <= arrBound) (return ())
859 assert (newEnd <= arrBound) (return ())
860 pokeWith arrContents arrEnd x
860 pokeWith arrContents arrEnd x
@@ -866,7 +866,7 @@ snocNewEnd newEnd arr@Array{..} x = liftIO $ do
867-- /Internal/
867-- /Internal/
868{-# INLINE snocUnsafe #-}
868{-# INLINE snocUnsafe #-}
869−snocUnsafe :: forall m a. (MonadIO m, Unboxed a) =>
869+snocUnsafe :: forall m a. (MonadIO m, Unbox a) =>
870 Array a -> a -> m (Array a)
870 Array a -> a -> m (Array a)
871snocUnsafe arr@Array{..} = snocNewEnd (INDEX_NEXT(arrEnd,a)) arr
871snocUnsafe arr@Array{..} = snocNewEnd (INDEX_NEXT(arrEnd,a)) arr
@@ -875,7 +875,7 @@ snocUnsafe arr@Array{..} = snocNewEnd (INDEX_NEXT(arrEnd,a)) arr
876-- /Internal/
876-- /Internal/
877{-# INLINE snocMay #-}
877{-# INLINE snocMay #-}
878−snocMay :: forall m a. (MonadIO m, Unboxed a) =>
878+snocMay :: forall m a. (MonadIO m, Unbox a) =>
879 Array a -> a -> m (Maybe (Array a))
879 Array a -> a -> m (Maybe (Array a))
880snocMay arr@Array{..} x = liftIO $ do
880snocMay arr@Array{..} x = liftIO $ do
881 let newEnd = INDEX_NEXT(arrEnd,a)
881 let newEnd = INDEX_NEXT(arrEnd,a)
@@ -885,7 +885,7 @@ snocMay arr@Array{..} x = liftIO $ do
886-- NOINLINE to move it out of the way and not pollute the instruction cache.
886-- NOINLINE to move it out of the way and not pollute the instruction cache.
887{-# NOINLINE snocWithRealloc #-}
887{-# NOINLINE snocWithRealloc #-}
888−snocWithRealloc :: forall m a. (MonadIO m, Unboxed a) =>
888+snocWithRealloc :: forall m a. (MonadIO m, Unbox a) =>
889 (Int -> Int)
889 (Int -> Int)
890 -> Array a
890 -> Array a
@@ -908,7 +908,7 @@ snocWithRealloc sizer arr x = do
909-- /Pre-release/
909-- /Pre-release/
910{-# INLINE snocWith #-}
910{-# INLINE snocWith #-}
911−snocWith :: forall m a. (MonadIO m, Unboxed a) =>
911+snocWith :: forall m a. (MonadIO m, Unbox a) =>
912 (Int -> Int)
912 (Int -> Int)
913 -> Array a
913 -> Array a
@@ -930,7 +930,7 @@ snocWith allocSize arr x = liftIO $ do
931-- /Pre-release/
931-- /Pre-release/
932{-# INLINE snocLinear #-}
932{-# INLINE snocLinear #-}
933−snocLinear :: forall m a. (MonadIO m, Unboxed a) => Array a -> a -> m (Array a)
933+snocLinear :: forall m a. (MonadIO m, Unbox a) => Array a -> a -> m (Array a)
934snocLinear = snocWith (+ allocBytesToBytes (undefined :: a) arrayChunkBytes)
934snocLinear = snocWith (+ allocBytesToBytes (undefined :: a) arrayChunkBytes)
936-- | The array is mutated to append an additional element to it. If there is no
936-- | The array is mutated to append an additional element to it. If there is no
@@ -947,7 +947,7 @@ snocLinear = snocWith (+ allocBytesToBytes (undefined :: a) arrayChunkBytes)
947-- Performs O(n * log n) copies to grow, but is liberal with memory allocation.
947-- Performs O(n * log n) copies to grow, but is liberal with memory allocation.
949{-# INLINE snoc #-}
949{-# INLINE snoc #-}
950−snoc :: forall m a. (MonadIO m, Unboxed a) => Array a -> a -> m (Array a)
950+snoc :: forall m a. (MonadIO m, Unbox a) => Array a -> a -> m (Array a)
951snoc = snocWith f
951snoc = snocWith f
@@ -967,7 +967,7 @@ snoc = snocWith f
968-- Unsafe because it does not check the bounds of the array.
968-- Unsafe because it does not check the bounds of the array.
969{-# INLINE_NORMAL getIndexUnsafe #-}
969{-# INLINE_NORMAL getIndexUnsafe #-}
970−getIndexUnsafe :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m a
970+getIndexUnsafe :: forall m a. (MonadIO m, Unbox a) => Int -> Array a -> m a
971getIndexUnsafe i Array{..} = do
971getIndexUnsafe i Array{..} = do
972 let index = INDEX_OF(arrStart,i,a)
972 let index = INDEX_OF(arrStart,i,a)
973 assert (i >= 0 && INDEX_VALID(index,arrEnd,a)) (return ())
973 assert (i >= 0 && INDEX_VALID(index,arrEnd,a)) (return ())
@@ -976,7 +976,7 @@ getIndexUnsafe i Array{..} = do
976-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
976-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
978{-# INLINE getIndex #-}
978{-# INLINE getIndex #-}
979−getIndex :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m a
979+getIndex :: forall m a. (MonadIO m, Unbox a) => Int -> Array a -> m a
980getIndex i Array{..} = do
980getIndex i Array{..} = do
981 let index = INDEX_OF(arrStart,i,a)
981 let index = INDEX_OF(arrStart,i,a)
982 if i >= 0 && INDEX_VALID(index,arrEnd,a)
982 if i >= 0 && INDEX_VALID(index,arrEnd,a)
@@ -989,7 +989,7 @@ getIndex i Array{..} = do
989-- Slightly faster than computing the forward index and using getIndex.
989-- Slightly faster than computing the forward index and using getIndex.
991{-# INLINE getIndexRev #-}
991{-# INLINE getIndexRev #-}
992−getIndexRev :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m a
992+getIndexRev :: forall m a. (MonadIO m, Unbox a) => Int -> Array a -> m a
993getIndexRev i Array{..} = do
993getIndexRev i Array{..} = do
994 let index = RINDEX_OF(arrEnd,i,a)
994 let index = RINDEX_OF(arrEnd,i,a)
995 if i >= 0 && index >= arrStart
995 if i >= 0 && index >= arrStart
@@ -1005,7 +1005,7 @@ data GetIndicesState contents start end st =
1006-- /Pre-release/
1006-- /Pre-release/
1007{-# INLINE getIndicesD #-}
1007{-# INLINE getIndicesD #-}
1008−getIndicesD :: (Monad m, Unboxed a) =>
1008+getIndicesD :: (Monad m, Unbox a) =>
1009 (forall b. IO b -> m b) -> D.Stream m Int -> Unfold m (Array a) a
1009 (forall b. IO b -> m b) -> D.Stream m Int -> Unfold m (Array a) a
1010getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
1010getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
@@ -1025,7 +1025,7 @@ getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
1025 D.Stop -> return D.Stop
1025 D.Stop -> return D.Stop
1027{-# INLINE getIndices #-}
1027{-# INLINE getIndices #-}
1028−getIndices :: (MonadIO m, Unboxed a) => Stream m Int -> Unfold m (Array a) a
1028+getIndices :: (MonadIO m, Unbox a) => Stream m Int -> Unfold m (Array a) a
1029getIndices = getIndicesD liftIO . Stream.toStreamD
1029getIndices = getIndicesD liftIO . Stream.toStreamD
1031-------------------------------------------------------------------------------
1031-------------------------------------------------------------------------------
@@ -1042,7 +1042,7 @@ getIndices = getIndicesD liftIO . Stream.toStreamD
1043-- /Pre-release/
1043-- /Pre-release/
1044{-# INLINE getSliceUnsafe #-}
1044{-# INLINE getSliceUnsafe #-}
1045−getSliceUnsafe :: forall a. Unboxed a
1045+getSliceUnsafe :: forall a. Unbox a
1046 => Int -- ^ from index
1046 => Int -- ^ from index
1047 -> Int -- ^ length of the slice
1047 -> Int -- ^ length of the slice
1048 -> Array a
1048 -> Array a
@@ -1061,7 +1061,7 @@ getSliceUnsafe index len (Array contents start e _) =
1062-- /Pre-release/
1062-- /Pre-release/
1063{-# INLINE getSlice #-}
1063{-# INLINE getSlice #-}
1064−getSlice :: forall a. Unboxed a =>
1064+getSlice :: forall a. Unbox a =>
1065 Int -- ^ from index
1065 Int -- ^ from index
1066 -> Int -- ^ length of the slice
1066 -> Int -- ^ length of the slice
1067 -> Array a
1067 -> Array a
@@ -1089,7 +1089,7 @@ getSlice index len (Array contents start e _) =
1089-- of cache locality and when you do not want to allocate additional memory.
1089-- of cache locality and when you do not want to allocate additional memory.
1091{-# INLINE reverse #-}
1091{-# INLINE reverse #-}
1092−reverse :: forall m a. (MonadIO m, Unboxed a) => Array a -> m ()
1092+reverse :: forall m a. (MonadIO m, Unbox a) => Array a -> m ()
1093reverse Array{..} = liftIO $ do
1093reverse Array{..} = liftIO $ do
1094 let l = arrStart
1094 let l = arrStart
1095 h = INDEX_PREV(arrEnd,a)
1095 h = INDEX_PREV(arrEnd,a)
@@ -1116,7 +1116,7 @@ permute = undefined
1117-- /Pre-release/
1117-- /Pre-release/
1118{-# INLINE partitionBy #-}
1118{-# INLINE partitionBy #-}
1119−partitionBy :: forall m a. (MonadIO m, Unboxed a)
1119+partitionBy :: forall m a. (MonadIO m, Unbox a)
1120 => (a -> Bool) -> Array a -> m (Array a, Array a)
1120 => (a -> Bool) -> Array a -> m (Array a, Array a)
1121partitionBy f arr@Array{..} = liftIO $ do
1121partitionBy f arr@Array{..} = liftIO $ do
1122 if arrStart >= arrEnd
1122 if arrStart >= arrEnd
@@ -1238,7 +1238,7 @@ byteLength Array{..} =
1238-- involves a costly division operation.
1238-- involves a costly division operation.
1240{-# INLINE length #-}
1240{-# INLINE length #-}
1241−length :: forall a. Unboxed a => Array a -> Int
1241+length :: forall a. Unbox a => Array a -> Int
1242length arr =
1242length arr =
1243 let elemSize = SIZE_OF(a)
1243 let elemSize = SIZE_OF(a)
1244 blen = byteLength arr
1244 blen = byteLength arr
@@ -1282,7 +1282,7 @@ data GroupState s contents start end bound
1283-- /Pre-release/
1283-- /Pre-release/
1284{-# INLINE_NORMAL arraysOf #-}
1284{-# INLINE_NORMAL arraysOf #-}
1285−arraysOf :: forall m a. (MonadIO m, Unboxed a)
1285+arraysOf :: forall m a. (MonadIO m, Unbox a)
1286 => Int -> D.Stream m a -> D.Stream m (Array a)
1286 => Int -> D.Stream m a -> D.Stream m (Array a)
1287-- XXX the idiomatic implementation leads to large regression in the D.reverse'
1287-- XXX the idiomatic implementation leads to large regression in the D.reverse'
1288-- benchmark. It seems it has difficulty producing optimized code when
1288-- benchmark. It seems it has difficulty producing optimized code when
@@ -1329,7 +1329,7 @@ arraysOf n (D.Stream step state) =
1329-- XXX buffer to a list instead?
1329-- XXX buffer to a list instead?
1330-- | Buffer the stream into arrays in memory.
1330-- | Buffer the stream into arrays in memory.
1331{-# INLINE arrayStreamKFromStreamD #-}
1331{-# INLINE arrayStreamKFromStreamD #-}
1332−arrayStreamKFromStreamD :: forall m a. (MonadIO m, Unboxed a) =>
1332+arrayStreamKFromStreamD :: forall m a. (MonadIO m, Unbox a) =>
1333 D.Stream m a -> m (K.Stream m (Array a))
1333 D.Stream m a -> m (K.Stream m (Array a))
1334arrayStreamKFromStreamD =
1334arrayStreamKFromStreamD =
1335 let n = allocBytesToElemCount (undefined :: a) defaultChunkSize
1335 let n = allocBytesToElemCount (undefined :: a) defaultChunkSize
@@ -1350,7 +1350,7 @@ data FlattenState s contents a =
1350-- We can try this if there are any fusion issues in the unfold.
1350-- We can try this if there are any fusion issues in the unfold.
1352{-# INLINE_NORMAL flattenArrays #-}
1352{-# INLINE_NORMAL flattenArrays #-}
1353−flattenArrays :: forall m a. (MonadIO m, Unboxed a)
1353+flattenArrays :: forall m a. (MonadIO m, Unbox a)
1354 => D.Stream m (Array a) -> D.Stream m a
1354 => D.Stream m (Array a) -> D.Stream m a
1355flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
1355flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
@@ -1379,7 +1379,7 @@ flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
1379-- We can try this if there are any fusion issues in the unfold.
1379-- We can try this if there are any fusion issues in the unfold.
1381{-# INLINE_NORMAL flattenArraysRev #-}
1381{-# INLINE_NORMAL flattenArraysRev #-}
1382−flattenArraysRev :: forall m a. (MonadIO m, Unboxed a)
1382+flattenArraysRev :: forall m a. (MonadIO m, Unbox a)
1383 => D.Stream m (Array a) -> D.Stream m a
1383 => D.Stream m (Array a) -> D.Stream m a
1384flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state)
1384flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state)
@@ -1417,7 +1417,7 @@ toArrayUnsafe (Array contents start end _) = ArrayUnsafe contents start end
1418fromArrayUnsafe ::
1418fromArrayUnsafe ::
1419#ifdef DEVBUILD
1419#ifdef DEVBUILD
1420− Unboxed a =>
1420+ Unbox a =>
1422 ArrayUnsafe a -> Array a
1422 ArrayUnsafe a -> Array a
1423fromArrayUnsafe (ArrayUnsafe contents start end) =
1423fromArrayUnsafe (ArrayUnsafe contents start end) =
@@ -1425,7 +1425,7 @@ fromArrayUnsafe (ArrayUnsafe contents start end) =
1426{-# INLINE_NORMAL producerWith #-}
1426{-# INLINE_NORMAL producerWith #-}
1427producerWith ::
1427producerWith ::
1428− forall m a. (Monad m, Unboxed a)
1428+ forall m a. (Monad m, Unbox a)
1429 => (forall b. IO b -> m b) -> Producer m (Array a) a
1429 => (forall b. IO b -> m b) -> Producer m (Array a) a
1430producerWith liftio = Producer step (return . toArrayUnsafe) extract
1430producerWith liftio = Producer step (return . toArrayUnsafe) extract
@@ -1446,18 +1446,18 @@ producerWith liftio = Producer step (return . toArrayUnsafe) extract
1446-- | Resumable unfold of an array.
1446-- | Resumable unfold of an array.
1448{-# INLINE_NORMAL producer #-}
1448{-# INLINE_NORMAL producer #-}
1449−producer :: forall m a. (MonadIO m, Unboxed a) => Producer m (Array a) a
1449+producer :: forall m a. (MonadIO m, Unbox a) => Producer m (Array a) a
1450producer = producerWith liftIO
1450producer = producerWith liftIO
1452-- | Unfold an array into a stream.
1452-- | Unfold an array into a stream.
1454{-# INLINE_NORMAL reader #-}
1454{-# INLINE_NORMAL reader #-}
1455−reader :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1455+reader :: forall m a. (MonadIO m, Unbox a) => Unfold m (Array a) a
1456reader = Producer.simplify producer
1456reader = Producer.simplify producer
1458{-# INLINE_NORMAL readerRevWith #-}
1458{-# INLINE_NORMAL readerRevWith #-}
1459readerRevWith ::
1459readerRevWith ::
1460− forall m a. (Monad m, Unboxed a)
1460+ forall m a. (Monad m, Unbox a)
1461 => (forall b. IO b -> m b) -> Unfold m (Array a) a
1461 => (forall b. IO b -> m b) -> Unfold m (Array a) a
1462readerRevWith liftio = Unfold step inject
1462readerRevWith liftio = Unfold step inject
@@ -1475,7 +1475,7 @@ readerRevWith liftio = Unfold step inject
1475-- | Unfold an array into a stream in reverse order.
1475-- | Unfold an array into a stream in reverse order.
1477{-# INLINE_NORMAL readerRev #-}
1477{-# INLINE_NORMAL readerRev #-}
1478−readerRev :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1478+readerRev :: forall m a. (MonadIO m, Unbox a) => Unfold m (Array a) a
1479readerRev = readerRevWith liftIO
1479readerRev = readerRevWith liftIO
1481-------------------------------------------------------------------------------
1481-------------------------------------------------------------------------------
@@ -1486,7 +1486,7 @@ readerRev = readerRevWith liftIO
1486-- Use foldr/build fusion to fuse with list consumers
1486-- Use foldr/build fusion to fuse with list consumers
1487-- This can be useful when using the IsList instance
1487-- This can be useful when using the IsList instance
1488{-# INLINE_LATE toListFB #-}
1488{-# INLINE_LATE toListFB #-}
1489−toListFB :: forall a b. Unboxed a => (a -> b -> b) -> b -> Array a -> b
1489+toListFB :: forall a b. Unbox a => (a -> b -> b) -> b -> Array a -> b
1490toListFB c n Array{..} = go arrStart
1490toListFB c n Array{..} = go arrStart
@@ -1510,7 +1510,7 @@ toListFB c n Array{..} = go arrStart
1510-- | Convert an 'Array' into a list.
1510-- | Convert an 'Array' into a list.
1512{-# INLINE toList #-}
1512{-# INLINE toList #-}
1513−toList :: forall m a. (MonadIO m, Unboxed a) => Array a -> m [a]
1513+toList :: forall m a. (MonadIO m, Unbox a) => Array a -> m [a]
1514toList Array{..} = liftIO $ go arrStart
1514toList Array{..} = liftIO $ go arrStart
@@ -1521,7 +1521,7 @@ toList Array{..} = liftIO $ go arrStart
1522{-# INLINE_NORMAL toStreamDWith #-}
1522{-# INLINE_NORMAL toStreamDWith #-}
1523toStreamDWith ::
1523toStreamDWith ::
1524− forall m a. (Monad m, Unboxed a)
1524+ forall m a. (Monad m, Unbox a)
1525 => (forall b. IO b -> m b) -> Array a -> D.Stream m a
1525 => (forall b. IO b -> m b) -> Array a -> D.Stream m a
1526toStreamDWith liftio Array{..} = D.Stream step arrStart
1526toStreamDWith liftio Array{..} = D.Stream step arrStart
@@ -1539,12 +1539,12 @@ toStreamDWith liftio Array{..} = D.Stream step arrStart
1540-- We can try this if the unfold has any performance issues.
1540-- We can try this if the unfold has any performance issues.
1541{-# INLINE_NORMAL toStreamD #-}
1541{-# INLINE_NORMAL toStreamD #-}
1542−toStreamD :: forall m a. (MonadIO m, Unboxed a) => Array a -> D.Stream m a
1542+toStreamD :: forall m a. (MonadIO m, Unbox a) => Array a -> D.Stream m a
1543toStreamD = toStreamDWith liftIO
1543toStreamD = toStreamDWith liftIO
1545{-# INLINE toStreamKWith #-}
1545{-# INLINE toStreamKWith #-}
1546toStreamKWith ::
1546toStreamKWith ::
1547− forall m a. (Monad m, Unboxed a)
1547+ forall m a. (Monad m, Unbox a)
1548 => (forall b. IO b -> m b) -> Array a -> K.Stream m a
1548 => (forall b. IO b -> m b) -> Array a -> K.Stream m a
1549toStreamKWith liftio Array{..} = go arrStart
1549toStreamKWith liftio Array{..} = go arrStart
@@ -1556,12 +1556,12 @@ toStreamKWith liftio Array{..} = go arrStart
1556 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
1556 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
1558{-# INLINE toStreamK #-}
1558{-# INLINE toStreamK #-}
1559−toStreamK :: forall m a. (MonadIO m, Unboxed a) => Array a -> K.Stream m a
1559+toStreamK :: forall m a. (MonadIO m, Unbox a) => Array a -> K.Stream m a
1560toStreamK = toStreamKWith liftIO
1560toStreamK = toStreamKWith liftIO
1562{-# INLINE_NORMAL toStreamDRevWith #-}
1562{-# INLINE_NORMAL toStreamDRevWith #-}
1563toStreamDRevWith ::
1563toStreamDRevWith ::
1564− forall m a. (Monad m, Unboxed a)
1564+ forall m a. (Monad m, Unbox a)
1565 => (forall b. IO b -> m b) -> Array a -> D.Stream m a
1565 => (forall b. IO b -> m b) -> Array a -> D.Stream m a
1566toStreamDRevWith liftio Array{..} =
1566toStreamDRevWith liftio Array{..} =
1567 let p = INDEX_PREV(arrEnd,a)
1567 let p = INDEX_PREV(arrEnd,a)
@@ -1581,12 +1581,12 @@ toStreamDRevWith liftio Array{..} =
1582-- We can try this if the unfold has any perf issues.
1582-- We can try this if the unfold has any perf issues.
1583{-# INLINE_NORMAL toStreamDRev #-}
1583{-# INLINE_NORMAL toStreamDRev #-}
1584−toStreamDRev :: forall m a. (MonadIO m, Unboxed a) => Array a -> D.Stream m a
1584+toStreamDRev :: forall m a. (MonadIO m, Unbox a) => Array a -> D.Stream m a
1585toStreamDRev = toStreamDRevWith liftIO
1585toStreamDRev = toStreamDRevWith liftIO
1587{-# INLINE toStreamKRevWith #-}
1587{-# INLINE toStreamKRevWith #-}
1588toStreamKRevWith ::
1588toStreamKRevWith ::
1589− forall m a. (Monad m, Unboxed a)
1589+ forall m a. (Monad m, Unbox a)
1590 => (forall b. IO b -> m b) -> Array a -> K.Stream m a
1590 => (forall b. IO b -> m b) -> Array a -> K.Stream m a
1591toStreamKRevWith liftio Array {..} =
1591toStreamKRevWith liftio Array {..} =
1592 let p = INDEX_PREV(arrEnd,a)
1592 let p = INDEX_PREV(arrEnd,a)
@@ -1600,7 +1600,7 @@ toStreamKRevWith liftio Array {..} =
1600 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
1600 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
1602{-# INLINE toStreamKRev #-}
1602{-# INLINE toStreamKRev #-}
1603−toStreamKRev :: forall m a. (MonadIO m, Unboxed a) => Array a -> K.Stream m a
1603+toStreamKRev :: forall m a. (MonadIO m, Unbox a) => Array a -> K.Stream m a
1604toStreamKRev = toStreamKRevWith liftIO
1604toStreamKRev = toStreamKRevWith liftIO
1606-------------------------------------------------------------------------------
1606-------------------------------------------------------------------------------
@@ -1612,12 +1612,12 @@ toStreamKRev = toStreamKRevWith liftIO
1613-- | Strict left fold of an array.
1613-- | Strict left fold of an array.
1614{-# INLINE_NORMAL foldl' #-}
1614{-# INLINE_NORMAL foldl' #-}
1615−foldl' :: (MonadIO m, Unboxed a) => (b -> a -> b) -> b -> Array a -> m b
1615+foldl' :: (MonadIO m, Unbox a) => (b -> a -> b) -> b -> Array a -> m b
1616foldl' f z arr = D.foldl' f z $ toStreamD arr
1616foldl' f z arr = D.foldl' f z $ toStreamD arr
1618-- | Right fold of an array.
1618-- | Right fold of an array.
1619{-# INLINE_NORMAL foldr #-}
1619{-# INLINE_NORMAL foldr #-}
1620−foldr :: (MonadIO m, Unboxed a) => (a -> b -> b) -> b -> Array a -> m b
1620+foldr :: (MonadIO m, Unbox a) => (a -> b -> b) -> b -> Array a -> m b
1621foldr f z arr = D.foldr f z $ toStreamD arr
1621foldr f z arr = D.foldr f z $ toStreamD arr
1623-------------------------------------------------------------------------------
1623-------------------------------------------------------------------------------
@@ -1641,7 +1641,7 @@ foldr f z arr = D.foldr f z $ toStreamD arr
1642-- /Internal/
1642-- /Internal/
1643{-# INLINE_NORMAL appendNUnsafe #-}
1643{-# INLINE_NORMAL appendNUnsafe #-}
1644−appendNUnsafe :: forall m a. (MonadIO m, Unboxed a) =>
1644+appendNUnsafe :: forall m a. (MonadIO m, Unbox a) =>
1645 m (Array a)
1645 m (Array a)
1647 -> Fold m a (Array a)
1647 -> Fold m a (Array a)
@@ -1673,7 +1673,7 @@ appendNUnsafe action n =
1673-- >>> appendN initial n = Fold.take n (Array.appendNUnsafe initial n)
1673-- >>> appendN initial n = Fold.take n (Array.appendNUnsafe initial n)
1675{-# INLINE_NORMAL appendN #-}
1675{-# INLINE_NORMAL appendN #-}
1676−appendN :: forall m a. (MonadIO m, Unboxed a) =>
1676+appendN :: forall m a. (MonadIO m, Unbox a) =>
1677 m (Array a) -> Int -> Fold m a (Array a)
1677 m (Array a) -> Int -> Fold m a (Array a)
1678appendN initial n = FL.take n (appendNUnsafe initial n)
1678appendN initial n = FL.take n (appendNUnsafe initial n)
@@ -1688,7 +1688,7 @@ appendN initial n = FL.take n (appendNUnsafe initial n)
1689-- /Pre-release/
1689-- /Pre-release/
1690{-# INLINE appendWith #-}
1690{-# INLINE appendWith #-}
1691−appendWith :: forall m a. (MonadIO m, Unboxed a) =>
1691+appendWith :: forall m a. (MonadIO m, Unbox a) =>
1692 (Int -> Int) -> m (Array a) -> Fold m a (Array a)
1692 (Int -> Int) -> m (Array a) -> Fold m a (Array a)
1693appendWith sizer = FL.foldlM' (snocWith sizer)
1693appendWith sizer = FL.foldlM' (snocWith sizer)
@@ -1701,7 +1701,7 @@ appendWith sizer = FL.foldlM' (snocWith sizer)
1701-- >>> append = Array.appendWith (* 2)
1701-- >>> append = Array.appendWith (* 2)
1703{-# INLINE append #-}
1703{-# INLINE append #-}
1704−append :: forall m a. (MonadIO m, Unboxed a) =>
1704+append :: forall m a. (MonadIO m, Unbox a) =>
1705 m (Array a) -> Fold m a (Array a)
1705 m (Array a) -> Fold m a (Array a)
1706append = appendWith (* 2)
1706append = appendWith (* 2)
@@ -1715,7 +1715,7 @@ append = appendWith (* 2)
1716-- /Pre-release/
1716-- /Pre-release/
1717{-# INLINE_NORMAL writeNWithUnsafe #-}
1717{-# INLINE_NORMAL writeNWithUnsafe #-}
1718−writeNWithUnsafe :: forall m a. (MonadIO m, Unboxed a)
1718+writeNWithUnsafe :: forall m a. (MonadIO m, Unbox a)
1719 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1719 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1720writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1720writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
@@ -1737,7 +1737,7 @@ writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1737-- >>> writeNUnsafe = Array.writeNWithUnsafe Array.newPinned
1737-- >>> writeNUnsafe = Array.writeNWithUnsafe Array.newPinned
1739{-# INLINE_NORMAL writeNUnsafe #-}
1739{-# INLINE_NORMAL writeNUnsafe #-}
1740−writeNUnsafe :: forall m a. (MonadIO m, Unboxed a)
1740+writeNUnsafe :: forall m a. (MonadIO m, Unbox a)
1741 => Int -> Fold m a (Array a)
1741 => Int -> Fold m a (Array a)
1742writeNUnsafe = writeNWithUnsafe newPinned
1742writeNUnsafe = writeNWithUnsafe newPinned
@@ -1748,7 +1748,7 @@ writeNUnsafe = writeNWithUnsafe newPinned
1748-- >>> writeNWith alloc n = Array.appendN (alloc n) n
1748-- >>> writeNWith alloc n = Array.appendN (alloc n) n
1750{-# INLINE_NORMAL writeNWith #-}
1750{-# INLINE_NORMAL writeNWith #-}
1751−writeNWith :: forall m a. (MonadIO m, Unboxed a)
1751+writeNWith :: forall m a. (MonadIO m, Unbox a)
1752 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1752 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1753writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
1753writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
@@ -1760,14 +1760,14 @@ writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
1760-- >>> writeN n = Array.appendN (Array.newPinned n) n
1760-- >>> writeN n = Array.appendN (Array.newPinned n) n
1762{-# INLINE_NORMAL writeN #-}
1762{-# INLINE_NORMAL writeN #-}
1763−writeN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
1763+writeN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
1764writeN = writeNWith newPinned
1764writeN = writeNWith newPinned
1766-- | Like writeNWithUnsafe but writes the array in reverse order.
1766-- | Like writeNWithUnsafe but writes the array in reverse order.
1768-- /Internal/
1768-- /Internal/
1769{-# INLINE_NORMAL writeRevNWithUnsafe #-}
1769{-# INLINE_NORMAL writeRevNWithUnsafe #-}
1770−writeRevNWithUnsafe :: forall m a. (MonadIO m, Unboxed a)
1770+writeRevNWithUnsafe :: forall m a. (MonadIO m, Unbox a)
1771 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1771 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1772writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1772writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
@@ -1788,7 +1788,7 @@ writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1789-- /Internal/
1789-- /Internal/
1790{-# INLINE_NORMAL writeRevNWith #-}
1790{-# INLINE_NORMAL writeRevNWith #-}
1791−writeRevNWith :: forall m a. (MonadIO m, Unboxed a)
1791+writeRevNWith :: forall m a. (MonadIO m, Unbox a)
1792 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1792 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1793writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
1793writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
@@ -1796,7 +1796,7 @@ writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
1797-- /Pre-release/
1797-- /Pre-release/
1798{-# INLINE_NORMAL writeRevN #-}
1798{-# INLINE_NORMAL writeRevN #-}
1799−writeRevN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
1799+writeRevN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
1800writeRevN = writeRevNWith newPinned
1800writeRevN = writeRevNWith newPinned
1802-- | @writeNAligned align n@ folds a maximum of @n@ elements from the input
1802-- | @writeNAligned align n@ folds a maximum of @n@ elements from the input
@@ -1808,7 +1808,7 @@ writeRevN = writeRevNWith newPinned
1808-- /Pre-release/
1808-- /Pre-release/
1810{-# INLINE_NORMAL writeNAligned #-}
1810{-# INLINE_NORMAL writeNAligned #-}
1811−writeNAligned :: forall m a. (MonadIO m, Unboxed a)
1811+writeNAligned :: forall m a. (MonadIO m, Unbox a)
1812 => Int -> Int -> Fold m a (Array a)
1812 => Int -> Int -> Fold m a (Array a)
1813writeNAligned align = writeNWith (newAlignedPinned align)
1813writeNAligned align = writeNWith (newAlignedPinned align)
@@ -1826,7 +1826,7 @@ writeNAligned align = writeNWith (newAlignedPinned align)
1826-- /Unimplemented/
1826-- /Unimplemented/
1828{-# INLINE_NORMAL writeChunks #-}
1828{-# INLINE_NORMAL writeChunks #-}
1829−writeChunks :: (MonadIO m, Unboxed a) =>
1829+writeChunks :: (MonadIO m, Unbox a) =>
1830 Int -> Fold m a (K.Stream n (Array a))
1830 Int -> Fold m a (K.Stream n (Array a))
1831writeChunks n = FL.many (writeN n) FL.toStreamK
1831writeChunks n = FL.many (writeN n) FL.toStreamK
@@ -1859,7 +1859,7 @@ writeChunks n = FL.many (writeN n) FL.toStreamK
1860-- /Pre-release/
1860-- /Pre-release/
1861{-# INLINE_NORMAL writeWith #-}
1861{-# INLINE_NORMAL writeWith #-}
1862−writeWith :: forall m a. (MonadIO m, Unboxed a)
1862+writeWith :: forall m a. (MonadIO m, Unbox a)
1863 => Int -> Fold m a (Array a)
1863 => Int -> Fold m a (Array a)
1864-- writeWith n = FL.rmapM rightSize $ appendWith (* 2) (newPinned n)
1864-- writeWith n = FL.rmapM rightSize $ appendWith (* 2) (newPinned n)
1865writeWith elemCount =
1865writeWith elemCount =
@@ -1897,7 +1897,7 @@ writeWith elemCount =
1897-- /Caution! Do not use this on infinite streams./
1897-- /Caution! Do not use this on infinite streams./
1899{-# INLINE write #-}
1899{-# INLINE write #-}
1900−write :: forall m a. (MonadIO m, Unboxed a) => Fold m a (Array a)
1900+write :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
1901write = writeWith (allocBytesToElemCount (undefined :: a) arrayChunkBytes)
1901write = writeWith (allocBytesToElemCount (undefined :: a) arrayChunkBytes)
1903-------------------------------------------------------------------------------
1903-------------------------------------------------------------------------------
@@ -1909,7 +1909,7 @@ write = writeWith (allocBytesToElemCount (undefined :: a) arrayChunkBytes)
1909-- >>> fromStreamDN n = StreamD.fold (Array.writeN n)
1909-- >>> fromStreamDN n = StreamD.fold (Array.writeN n)
1911{-# INLINE_NORMAL fromStreamDN #-}
1911{-# INLINE_NORMAL fromStreamDN #-}
1912−fromStreamDN :: forall m a. (MonadIO m, Unboxed a)
1912+fromStreamDN :: forall m a. (MonadIO m, Unbox a)
1913 => Int -> D.Stream m a -> m (Array a)
1913 => Int -> D.Stream m a -> m (Array a)
1914-- fromStreamDN n = D.fold (writeN n)
1914-- fromStreamDN n = D.fold (writeN n)
1915fromStreamDN limit str = do
1915fromStreamDN limit str = do
@@ -1928,14 +1928,14 @@ fromStreamDN limit str = do
1928-- array may hold less than N elements.
1928-- array may hold less than N elements.
1930{-# INLINABLE fromListN #-}
1930{-# INLINABLE fromListN #-}
1931−fromListN :: (MonadIO m, Unboxed a) => Int -> [a] -> m (Array a)
1931+fromListN :: (MonadIO m, Unbox a) => Int -> [a] -> m (Array a)
1932fromListN n xs = fromStreamDN n $ D.fromList xs
1932fromListN n xs = fromStreamDN n $ D.fromList xs
1934-- | Like fromListN but writes the array in reverse order.
1934-- | Like fromListN but writes the array in reverse order.
1936-- /Pre-release/
1936-- /Pre-release/
1937{-# INLINE fromListRevN #-}
1937{-# INLINE fromListRevN #-}
1938−fromListRevN :: (MonadIO m, Unboxed a) => Int -> [a] -> m (Array a)
1938+fromListRevN :: (MonadIO m, Unbox a) => Int -> [a] -> m (Array a)
1939fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
1939fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
1941-------------------------------------------------------------------------------
1941-------------------------------------------------------------------------------
@@ -1943,14 +1943,14 @@ fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
1943-------------------------------------------------------------------------------
1943-------------------------------------------------------------------------------
1945{-# INLINE arrayStreamKLength #-}
1945{-# INLINE arrayStreamKLength #-}
1946−arrayStreamKLength :: (Monad m, Unboxed a) => K.Stream m (Array a) -> m Int
1946+arrayStreamKLength :: (Monad m, Unbox a) => K.Stream m (Array a) -> m Int
1947arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
1947arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
1949-- | Convert an array stream to an array. Note that this requires peak memory
1949-- | Convert an array stream to an array. Note that this requires peak memory
1950-- that is double the size of the array stream.
1950-- that is double the size of the array stream.
1952{-# INLINE fromArrayStreamK #-}
1952{-# INLINE fromArrayStreamK #-}
1953−fromArrayStreamK :: (Unboxed a, MonadIO m) =>
1953+fromArrayStreamK :: (Unbox a, MonadIO m) =>
1954 K.Stream m (Array a) -> m (Array a)
1954 K.Stream m (Array a) -> m (Array a)
1955fromArrayStreamK as = do
1955fromArrayStreamK as = do
1956 len <- arrayStreamKLength as
1956 len <- arrayStreamKLength as
@@ -1970,13 +1970,13 @@ fromArrayStreamK as = do
1970-- >>> fromStreamD = StreamD.fold Array.write
1970-- >>> fromStreamD = StreamD.fold Array.write
1972{-# INLINE fromStreamD #-}
1972{-# INLINE fromStreamD #-}
1973−fromStreamD :: (MonadIO m, Unboxed a) => D.Stream m a -> m (Array a)
1973+fromStreamD :: (MonadIO m, Unbox a) => D.Stream m a -> m (Array a)
1974fromStreamD m = arrayStreamKFromStreamD m >>= fromArrayStreamK
1974fromStreamD m = arrayStreamKFromStreamD m >>= fromArrayStreamK
1976-- | Create an 'Array' from a list. The list must be of finite size.
1976-- | Create an 'Array' from a list. The list must be of finite size.
1978{-# INLINE fromList #-}
1978{-# INLINE fromList #-}
1979−fromList :: (MonadIO m, Unboxed a) => [a] -> m (Array a)
1979+fromList :: (MonadIO m, Unbox a) => [a] -> m (Array a)
1980fromList xs = fromStreamD $ D.fromList xs
1980fromList xs = fromStreamD $ D.fromList xs
1982-- XXX We are materializing the whole list first for getting the length. Check
1982-- XXX We are materializing the whole list first for getting the length. Check
@@ -1984,7 +1984,7 @@ fromList xs = fromStreamD $ D.fromList xs
1985-- | Like 'fromList' but writes the contents of the list in reverse order.
1985-- | Like 'fromList' but writes the contents of the list in reverse order.
1986{-# INLINE fromListRev #-}
1986{-# INLINE fromListRev #-}
1987−fromListRev :: (MonadIO m, Unboxed a) => [a] -> m (Array a)
1987+fromListRev :: (MonadIO m, Unbox a) => [a] -> m (Array a)
1988fromListRev xs = fromListRevN (Prelude.length xs) xs
1988fromListRev xs = fromListRevN (Prelude.length xs) xs
1990-------------------------------------------------------------------------------
1990-------------------------------------------------------------------------------
@@ -2009,7 +2009,7 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
2010-- | Copy two arrays into a newly allocated array.
2010-- | Copy two arrays into a newly allocated array.
2011{-# INLINE spliceCopy #-}
2011{-# INLINE spliceCopy #-}
2012−spliceCopy :: forall m a. (MonadIO m, Unboxed a) =>
2012+spliceCopy :: forall m a. (MonadIO m, Unbox a) =>
2013 Array a -> Array a -> m (Array a)
2013 Array a -> Array a -> m (Array a)
2014spliceCopy arr1 arr2 = liftIO $ do
2014spliceCopy arr1 arr2 = liftIO $ do
2015 let start1 = arrStart arr1
2015 let start1 = arrStart arr1
@@ -2051,7 +2051,7 @@ spliceUnsafe dst src =
2052-- /Pre-release/
2052-- /Pre-release/
2053{-# INLINE spliceWith #-}
2053{-# INLINE spliceWith #-}
2054−spliceWith :: forall m a. (MonadIO m, Unboxed a) =>
2054+spliceWith :: forall m a. (MonadIO m, Unbox a) =>
2055 (Int -> Int -> Int) -> Array a -> Array a -> m (Array a)
2055 (Int -> Int -> Int) -> Array a -> Array a -> m (Array a)
2056spliceWith sizer dst@(Array _ start end bound) src = do
2056spliceWith sizer dst@(Array _ start end bound) src = do
@@ -2085,7 +2085,7 @@ spliceWith sizer dst@(Array _ start end bound) src = do
2086-- /Pre-release/
2086-- /Pre-release/
2087{-# INLINE splice #-}
2087{-# INLINE splice #-}
2088−splice :: (MonadIO m, Unboxed a) => Array a -> Array a -> m (Array a)
2088+splice :: (MonadIO m, Unbox a) => Array a -> Array a -> m (Array a)
2089splice = spliceWith (+)
2089splice = spliceWith (+)
2091-- | Like 'append' but the growth of the array is exponential. Whenever a new
2091-- | Like 'append' but the growth of the array is exponential. Whenever a new
@@ -2099,7 +2099,7 @@ splice = spliceWith (+)
2100-- /Pre-release/
2100-- /Pre-release/
2101{-# INLINE spliceExp #-}
2101{-# INLINE spliceExp #-}
2102−spliceExp :: (MonadIO m, Unboxed a) => Array a -> Array a -> m (Array a)
2102+spliceExp :: (MonadIO m, Unbox a) => Array a -> Array a -> m (Array a)
2103spliceExp = spliceWith (\l1 l2 -> max (l1 * 2) (l1 + l2))
2103spliceExp = spliceWith (\l1 l2 -> max (l1 * 2) (l1 + l2))
2105-------------------------------------------------------------------------------
2105-------------------------------------------------------------------------------
@@ -2137,7 +2137,7 @@ breakOn sep arr@Array{..} = asPtrUnsafe arr $ \p -> liftIO $ do
2137-- | Create two slices of an array without copying the original array. The
2137-- | Create two slices of an array without copying the original array. The
2138-- specified index @i@ is the first index of the second slice.
2138-- specified index @i@ is the first index of the second slice.
2140−splitAt :: forall a. Unboxed a => Int -> Array a -> (Array a, Array a)
2140+splitAt :: forall a. Unbox a => Int -> Array a -> (Array a, Array a)
2141splitAt i arr@Array{..} =
2141splitAt i arr@Array{..} =
2142 let maxIndex = length arr - 1
2142 let maxIndex = length arr - 1
2143 in if i < 0
2143 in if i < 0
@@ -2189,7 +2189,7 @@ asBytes = castUnsafe
2189-- type @b@. The length of the array should be a multiple of the size of the
2189-- type @b@. The length of the array should be a multiple of the size of the
2190-- target element otherwise 'Nothing' is returned.
2190-- target element otherwise 'Nothing' is returned.
2192−cast :: forall a b. Unboxed b => Array a -> Maybe (Array b)
2192+cast :: forall a b. Unbox b => Array a -> Maybe (Array b)
2193cast arr =
2193cast arr =
2194 let len = byteLength arr
2194 let len = byteLength arr
2195 r = len `mod` SIZE_OF(b)
2195 r = len `mod` SIZE_OF(b)
@@ -2278,7 +2278,7 @@ cmp arr1 arr2 =
2278-- NFData
2278-- NFData
2279-------------------------------------------------------------------------------
2279-------------------------------------------------------------------------------
2281−-- This is an Unboxed array, we cannot have unevaluated data in it so this is
2281+-- This is an Unbox array, we cannot have unevaluated data in it so this is
2282-- just a no op.
2282-- just a no op.
2283instance NFData (Array a) where
2283instance NFData (Array a) where
2284 {-# INLINE rnf #-}
2284 {-# INLINE rnf #-}
@@ -2292,7 +2292,7 @@ instance NFData1 Array where
2293-- /Pre-release/
2293-- /Pre-release/
2294{-# INLINE strip #-}
2294{-# INLINE strip #-}
2295−strip :: forall a m. (Unboxed a, MonadIO m) =>
2295+strip :: forall a m. (Unbox a, MonadIO m) =>
2296 (a -> Bool) -> Array a -> m (Array a)
2296 (a -> Bool) -> Array a -> m (Array a)
2297strip eq arr@Array{..} = liftIO $ do
2297strip eq arr@Array{..} = liftIO $ do
2298 st <- getStart arrStart
2298 st <- getStart arrStart
@@ -2336,7 +2336,7 @@ strip eq arr@Array{..} = liftIO $ do
2337-- /Pre-release/
2337-- /Pre-release/
2338{-# INLINE bubble #-}
2338{-# INLINE bubble #-}
2339−bubble :: (MonadIO m, Unboxed a) => (a -> a -> Ordering) -> Array a -> m ()
2339+bubble :: (MonadIO m, Unbox a) => (a -> a -> Ordering) -> Array a -> m ()
2340bubble cmp0 arr =
2340bubble cmp0 arr =
2341 when (l > 1) $ do
2341 when (l > 1) $ do
2342 x <- getIndexUnsafe (l - 1) arr
2342 x <- getIndexUnsafe (l - 1) arr