@@ -28,7 +28,7 @@
29module Streamly.Internal.Data.MutArray.Type
29module Streamly.Internal.Data.MutArray.Type
31− -- * Type
31+ -- ** Type
32 -- $arrayNotes
32 -- $arrayNotes
33 MutArray (..)
33 MutArray (..)
34 , MutByteArray
34 , MutByteArray
@@ -37,7 +37,7 @@ module Streamly.Internal.Data.MutArray.Type
38 , isPinned
38 , isPinned
40− -- * Constructing and Writing
40+ -- -- * Constructing and Writing
41 -- ** Construction
41 -- ** Construction
@@ -65,7 +65,7 @@ module Streamly.Internal.Data.MutArray.Type
65 , writeRevN
65 , writeRevN
66 -- , writeRev
66 -- , writeRev
68− -- ** From containers
68+ -- *** From containers
69 , fromListN
69 , fromListN
70 , pinnedFromListN
70 , pinnedFromListN
71 , fromList
71 , fromList
@@ -76,7 +76,7 @@ module Streamly.Internal.Data.MutArray.Type
76 , fromStreamD
76 , fromStreamD
77 , fromPureStream
77 , fromPureStream
79− -- * Random writes
79+ -- ** Random writes
80 , putIndex
80 , putIndex
81 , putIndexUnsafe
81 , putIndexUnsafe
82 , putIndices
82 , putIndices
@@ -93,32 +93,32 @@ module Streamly.Internal.Data.MutArray.Type
93 , swapIndices
93 , swapIndices
94 , unsafeSwapIndices
94 , unsafeSwapIndices
96− -- * Growing and Shrinking
96+ -- ** Growing and Shrinking
97− -- Arrays grow only at the end, though it is possible to grow on both sides
97+ -- | Arrays grow only at the end, though it is possible to grow on both sides
98 -- and therefore have a cons as well as snoc. But that will require two
98 -- and therefore have a cons as well as snoc. But that will require two
99 -- bounds in the array representation.
99 -- bounds in the array representation.
101− -- ** Appending elements
101+ -- *** Appending elements
102 , snocWith
102 , snocWith
104 , snocLinear
104 , snocLinear
105 , snocMay
105 , snocMay
106 , snocUnsafe
106 , snocUnsafe
108− -- ** Appending streams
108+ -- *** Appending streams
109 , writeAppendNUnsafe
109 , writeAppendNUnsafe
110 , writeAppendN
110 , writeAppendN
111 , writeAppendWith
111 , writeAppendWith
112 , writeAppend
112 , writeAppend
114− -- * Eliminating and Reading
114+ -- ** Eliminating and Reading
116− -- ** To streams
116+ -- *** To streams
118 , readerRevWith
118 , readerRevWith
119 , readerRev
119 , readerRev
121− -- ** To containers
121+ -- *** To containers
122 , toStreamDWith
122 , toStreamDWith
123 , toStreamDRevWith
123 , toStreamDRevWith
124 , toStreamKWith
124 , toStreamKWith
@@ -133,7 +133,7 @@ module Streamly.Internal.Data.MutArray.Type
133 , producerWith
133 , producerWith
134 , producer
134 , producer
136− -- ** Random reads
136+ -- *** Random reads
137 , getIndex
137 , getIndex
138 , getIndexUnsafe
138 , getIndexUnsafe
139 , getIndices
139 , getIndices
@@ -141,7 +141,7 @@ module Streamly.Internal.Data.MutArray.Type
141 -- , getFromThenTo
141 -- , getFromThenTo
142 , getIndexRev
142 , getIndexRev
144− -- * Memory Management
144+ -- ** Memory Management
145 , blockSize
145 , blockSize
146 , arrayChunkBytes
146 , arrayChunkBytes
147 , allocBytesToElemCount
147 , allocBytesToElemCount
@@ -150,14 +150,14 @@ module Streamly.Internal.Data.MutArray.Type
150 , resizeExp
150 , resizeExp
151 , rightSize
151 , rightSize
153− -- * Size
153+ -- ** Size
155 , byteLength
155 , byteLength
156 -- , capacity
156 -- , capacity
157 , byteCapacity
157 , byteCapacity
158 , bytesFree
158 , bytesFree
160− -- * In-place Mutation Algorithms
160+ -- ** In-place Mutation Algorithms
162 , reverse
162 , reverse
163 , permute
163 , permute
@@ -167,18 +167,18 @@ module Streamly.Internal.Data.MutArray.Type
167 , mergeBy
167 , mergeBy
170− -- * Casting
170+ -- ** Casting
172 , castUnsafe
172 , castUnsafe
173 , asBytes
173 , asBytes
174 , asPtrUnsafe
174 , asPtrUnsafe
176− -- * Folding
176+ -- ** Folding
181− -- * Arrays of arrays
181+ -- ** Arrays of arrays
182 -- We can add dimensionality parameter to the array type to get
182 -- We can add dimensionality parameter to the array type to get
183 -- multidimensional arrays. Multidimensional arrays would just be a
183 -- multidimensional arrays. Multidimensional arrays would just be a
184 -- convenience wrapper on top of single dimensional arrays.
184 -- convenience wrapper on top of single dimensional arrays.
@@ -186,17 +186,17 @@ module Streamly.Internal.Data.MutArray.Type
186 -- | Operations dealing with multiple arrays, streams of arrays or
186 -- | Operations dealing with multiple arrays, streams of arrays or
187 -- multidimensional array representations.
187 -- multidimensional array representations.
189− -- ** Construct from streams
189+ -- *** Construct from streams
190 , chunksOf
190 , chunksOf
191 , pinnedChunksOf
191 , pinnedChunksOf
192 , writeChunks
192 , writeChunks
194− -- ** Eliminate to streams
194+ -- *** Eliminate to streams
195 , flattenArrays
195 , flattenArrays
196 , flattenArraysRev
196 , flattenArraysRev
197 , fromArrayStreamK
197 , fromArrayStreamK
199− -- ** Construct from arrays
199+ -- *** Construct from arrays
200 -- get chunks without copying
200 -- get chunks without copying
201 , getSliceUnsafe
201 , getSliceUnsafe
202 , getSlice
202 , getSlice
@@ -218,7 +218,7 @@ module Streamly.Internal.Data.MutArray.Type
218 -- , appendSlice
218 -- , appendSlice
219 -- , appendSliceFrom
219 -- , appendSliceFrom
221− -- * Utilities
221+ -- ** Utilities
222 , roundUpToPower2
222 , roundUpToPower2
@@ -357,8 +357,8 @@ data MutArray a =
357-- Pinning & Unpinning
357-- Pinning & Unpinning
358-------------------------------------------------------------------------------
358-------------------------------------------------------------------------------
360−-- | Copy the 'MutArray' to pinned memory if unpinned, else do nothing. The
360+-- | Return a copy of the array in pinned memory if unpinned, else return the
361−-- overhead is a copy if the input array is unpinned.
361+-- original array.
362{-# INLINE pin #-}
362{-# INLINE pin #-}
363pin :: MutArray a -> IO (MutArray a)
363pin :: MutArray a -> IO (MutArray a)
364pin arr@MutArray{..} =
364pin arr@MutArray{..} =
@@ -366,8 +366,8 @@ pin arr@MutArray{..} =
366 then pure arr
366 then pure arr
367 else pinnedClone arr
367 else pinnedClone arr
369−-- | Copy the 'MutArray' to unpinned memory if pinned, else do nothing. The
369+-- | Return a copy of the array in unpinned memory if pinned, else return the
370−-- overhead is a copy if the input array is pinned.
370+-- original array.
371{-# INLINE unpin #-}
371{-# INLINE unpin #-}
372unpin :: MutArray a -> IO (MutArray a)
372unpin :: MutArray a -> IO (MutArray a)
373unpin arr@MutArray{..} =
373unpin arr@MutArray{..} =
@@ -375,6 +375,7 @@ unpin arr@MutArray{..} =
375 then clone arr
375 then clone arr
376 else pure arr
376 else pure arr
378+-- | Return 'True' if the array is allocated in pinned memory.
378{-# INLINE isPinned #-}
379{-# INLINE isPinned #-}
379isPinned :: MutArray a -> Bool
380isPinned :: MutArray a -> Bool
380isPinned MutArray{..} = Unboxed.isPinned arrContents
381isPinned MutArray{..} = Unboxed.isPinned arrContents