Cleanup and make consistent the export lists of Array modules

This commit is contained in:
Harendra Kumar 2024-01-01 07:54:10 +05:30
parent ffea484db8
commit 11845277c7
5 changed files with 192 additions and 152 deletions

View File

@ -33,7 +33,6 @@ import qualified Streamly.Data.Stream as Stream
import qualified Streamly.Data.Fold as Fold
import qualified Streamly.FileSystem.Handle as FH
import qualified Streamly.Internal.Data.Array as A
import qualified Streamly.Internal.Data.Array as AT
import qualified Streamly.Internal.Data.Fold as FL
import qualified Streamly.Internal.Data.Stream as IP
import qualified Streamly.Internal.FileSystem.Handle as IFH
@ -48,7 +47,7 @@ import Streamly.Benchmark.Common.Handle
#ifdef INSPECTION
import Streamly.Internal.Data.Stream (Step(..), FoldMany)
import qualified Streamly.Internal.Data.MutArray as MA
import qualified Streamly.Internal.Data.MutArray as MutArray
import qualified Streamly.Internal.Data.Stream as D
import qualified Streamly.Internal.Data.Unfold as IUF
@ -69,7 +68,7 @@ readLast = S.fold Fold.last . S.unfold FH.reader
inspect $ hasNoTypeClasses 'readLast
inspect $ 'readLast `hasNoType` ''Step -- S.unfold
inspect $ 'readLast `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
inspect $ 'readLast `hasNoType` ''MA.ArrayUnsafe -- FH.read/A.read
inspect $ 'readLast `hasNoType` ''MutArray.ArrayUnsafe -- FH.read/A.read
#endif
-- assert that flattenArrays constructors are not present
@ -81,7 +80,7 @@ readCountBytes = S.fold Fold.length . S.unfold FH.reader
inspect $ hasNoTypeClasses 'readCountBytes
inspect $ 'readCountBytes `hasNoType` ''Step -- S.unfold
inspect $ 'readCountBytes `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
inspect $ 'readCountBytes `hasNoType` ''MA.ArrayUnsafe -- FH.read/A.read
inspect $ 'readCountBytes `hasNoType` ''MutArray.ArrayUnsafe -- FH.read/A.read
#endif
-- | Count the number of lines in a file.
@ -96,7 +95,7 @@ readCountLines =
inspect $ hasNoTypeClasses 'readCountLines
inspect $ 'readCountLines `hasNoType` ''Step
inspect $ 'readCountLines `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
inspect $ 'readCountLines `hasNoType` ''MA.ArrayUnsafe -- FH.read/A.read
inspect $ 'readCountLines `hasNoType` ''MutArray.ArrayUnsafe -- FH.read/A.read
#endif
-- | Count the number of words in a file.
@ -120,7 +119,7 @@ readSumBytes = S.fold Fold.sum . S.unfold FH.reader
inspect $ hasNoTypeClasses 'readSumBytes
inspect $ 'readSumBytes `hasNoType` ''Step
inspect $ 'readSumBytes `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
inspect $ 'readSumBytes `hasNoType` ''MA.ArrayUnsafe -- FH.read/A.read
inspect $ 'readSumBytes `hasNoType` ''MutArray.ArrayUnsafe -- FH.read/A.read
#endif
-- XXX When we mark this with INLINE and we have two benchmarks using S.drain
@ -236,13 +235,13 @@ groupsOf :: Int -> Handle -> IO Int
groupsOf n inh =
-- writeNUnsafe gives 2.5x boost here over writeN.
S.fold Fold.length
$ IP.groupsOf n (AT.writeNUnsafe n) (S.unfold FH.reader inh)
$ IP.groupsOf n (A.writeNUnsafe n) (S.unfold FH.reader inh)
#ifdef INSPECTION
inspect $ hasNoTypeClasses 'groupsOf
inspect $ 'groupsOf `hasNoType` ''Step
inspect $ 'groupsOf `hasNoType` ''FoldMany
inspect $ 'groupsOf `hasNoType` ''AT.ArrayUnsafe -- AT.writeNUnsafe
inspect $ 'groupsOf `hasNoType` ''MutArray.ArrayUnsafe -- AT.writeNUnsafe
-- FH.read/A.read
inspect $ 'groupsOf `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
#endif

View File

@ -42,8 +42,7 @@ import Streamly.Internal.Data.Stream (Step(..))
import qualified Streamly.Internal.Data.Stream as D
import qualified Streamly.Internal.Data.Tuple.Strict as Strict
import qualified Streamly.Internal.Data.MutArray.Stream as MAS
import qualified Streamly.Internal.Data.Array as AT
import qualified Streamly.Internal.Data.MutArray as MutArray
import Test.Inspection
#endif
@ -83,7 +82,7 @@ copyStream inh outh = S.fold (FH.write outh) (S.unfold FH.reader inh)
inspect $ hasNoTypeClasses 'copyStream
inspect $ 'copyStream `hasNoType` ''Step -- S.unfold
inspect $ 'copyStream `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
inspect $ 'copyStream `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
inspect $ 'copyStream `hasNoType` ''MutArray.ArrayUnsafe -- FH.write/writeNUnsafe
-- FH.read/A.read
inspect $ 'copyStream `hasNoType` ''Strict.Tuple3' -- FH.write/chunksOf
#endif
@ -109,8 +108,8 @@ readFromBytesNull inh devNull = IFH.putBytes devNull $ S.unfold FH.reader inh
#ifdef INSPECTION
inspect $ hasNoTypeClasses 'readFromBytesNull
inspect $ 'readFromBytesNull `hasNoType` ''Step
inspect $ 'readFromBytesNull `hasNoType` ''MAS.SpliceState
inspect $ 'readFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.chunksOf
inspect $ 'readFromBytesNull `hasNoType` ''MutArray.SpliceState
inspect $ 'readFromBytesNull `hasNoType` ''MutArray.ArrayUnsafe -- FH.fromBytes/S.chunksOf
inspect $ 'readFromBytesNull `hasNoType` ''D.FoldMany
#endif
@ -123,8 +122,8 @@ readWithFromBytesNull inh devNull =
#ifdef INSPECTION
inspect $ hasNoTypeClasses 'readWithFromBytesNull
inspect $ 'readWithFromBytesNull `hasNoType` ''Step
inspect $ 'readWithFromBytesNull `hasNoType` ''MAS.SpliceState
inspect $ 'readWithFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.chunksOf
inspect $ 'readWithFromBytesNull `hasNoType` ''MutArray.SpliceState
inspect $ 'readWithFromBytesNull `hasNoType` ''MutArray.ArrayUnsafe -- FH.fromBytes/S.chunksOf
inspect $ 'readWithFromBytesNull `hasNoType` ''D.FoldMany
#endif
@ -171,7 +170,7 @@ writeReadWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
inspect $ hasNoTypeClasses 'writeReadWith
inspect $ 'writeReadWith `hasNoType` ''Step
inspect $ 'writeReadWith `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
inspect $ 'writeReadWith `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
inspect $ 'writeReadWith `hasNoType` ''MutArray.ArrayUnsafe -- FH.write/writeNUnsafe
-- FH.read/A.read
#endif
@ -188,7 +187,7 @@ writeRead inh devNull = IUF.fold fld unf inh
inspect $ hasNoTypeClasses 'writeRead
inspect $ 'writeRead `hasNoType` ''Step
inspect $ 'writeRead `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
inspect $ 'writeRead `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
inspect $ 'writeRead `hasNoType` ''MutArray.ArrayUnsafe -- FH.write/writeNUnsafe
-- FH.read/A.read
#endif

View File

@ -45,9 +45,10 @@ import Streamly.Benchmark.Common.Handle
#ifdef INSPECTION
import Streamly.Internal.Data.MutByteArray (Unbox)
import Streamly.Internal.Data.Stream (Step(..))
import qualified Streamly.Internal.Data.Array as Array
import qualified Streamly.Internal.Data.MutArray as MutArray
import qualified Streamly.Internal.Data.Fold as Fold
import qualified Streamly.Internal.Data.Tuple.Strict as Strict
import qualified Streamly.Internal.Data.Array as Array
import Test.Inspection
#endif
@ -223,7 +224,7 @@ inspect $ 'copyStreamLatin1' `hasNoType` ''Step
inspect $ 'copyStreamLatin1' `hasNoType` ''Unfold.ConcatState -- Handle.read/UF.many
inspect $ 'copyStreamLatin1' `hasNoType` ''Fold.Step
inspect $ 'copyStreamLatin1' `hasNoType` ''Array.ArrayUnsafe -- Handle.write/writeNUnsafe
inspect $ 'copyStreamLatin1' `hasNoType` ''MutArray.ArrayUnsafe -- Handle.write/writeNUnsafe
-- Handle.read/Array.read
inspect $ 'copyStreamLatin1' `hasNoType` ''Strict.Tuple3' -- Handle.write/chunksOf
#endif
@ -244,7 +245,7 @@ inspect $ 'copyStreamLatin1 `hasNoType` ''Unfold.ConcatState -- Handle.read/UF.m
inspect $ 'copyStreamLatin1 `hasNoType` ''Fold.ManyState
inspect $ 'copyStreamLatin1 `hasNoType` ''Fold.Step
inspect $ 'copyStreamLatin1 `hasNoType` ''Array.ArrayUnsafe -- Handle.write/writeNUnsafe
inspect $ 'copyStreamLatin1 `hasNoType` ''MutArray.ArrayUnsafe -- Handle.write/writeNUnsafe
-- Handle.read/Array.read
inspect $ 'copyStreamLatin1 `hasNoType` ''Strict.Tuple3' -- Handle.write/chunksOf
#endif

View File

@ -2,7 +2,6 @@
-- |
-- Module : Streamly.Internal.Data.Array.Type
-- Copyright : (c) 2020 Composewell Technologies
--
-- License : BSD3-3-Clause
-- Maintainer : streamly@composewell.com
-- Stability : experimental
@ -10,72 +9,42 @@
--
-- See notes in "Streamly.Internal.Data.MutArray.Type"
--
module Streamly.Internal.Data.Array.Type
(
-- ** Type
-- $arrayNotes
Array (..)
, asPtrUnsafe
, nil
-- ** Freezing and Thawing
-- ** Conversion
-- *** Mutable and Immutable
, unsafeFreeze
, unsafeFreezeWithShrink
, unsafeThaw
-- ** Pinning and Unpinning
-- *** Pinned and Unpinned
, pin
, unpin
, isPinned
-- *** Casting
, asPtrUnsafe
-- ** Construction
, splice
, nil
, fromList
, pinnedFromList
, fromListN
, pinnedFromListN
, fromListRev
, fromListRevN
, fromStreamN
, fromStream
, fromPureStreamN
, fromPureStream
, fromByteStr#
, fromByteStr
, fromPtrN
, fromChunksK
-- ** Split
, breakOn
, splitAt
-- ** Cloning arrays
-- *** Cloning
-- XXX Why would we clone an immutable array?
, clone
, pinnedClone
-- * Unfolds
, reader
, readerUnsafe
, producer -- experimental
-- *** Slicing
-- | Get a subarray without copying
, splitAt
, breakOn -- XXX requires MonadIO
-- ** Elimination
, unsafeIndexIO
, getIndexUnsafe
, byteLength
, length
, foldl'
, foldr
, toStreamK
, toStreamKRev
, read
, readRev
, readerRev
, toList
-- ** Folds
-- *** Stream Folds
, unsafeMakePure
, writeWith
, writeN
, pinnedWriteN
@ -85,17 +54,75 @@ module Streamly.Internal.Data.Array.Type
, pinnedWriteNAligned
, write
, pinnedWrite
, unsafeMakePure
-- *** From containers
, fromListN
, pinnedFromListN
, fromList
, pinnedFromList
, fromListRevN
, fromListRev
, fromStreamN
, fromStream
, fromPureStreamN
, fromPureStream
, fromByteStr#
, fromByteStr
, fromPtrN
, fromChunksK
-- ** Reading
-- *** Indexing
, unsafeIndexIO -- XXX rename to getIndexUnsafeIO
, getIndexUnsafe
-- *** To Streams
, read
, readRev
, toStreamK
, toStreamKRev
-- *** To Containers
, toList
-- *** Unfolds
, producer -- experimental
, readerUnsafe
, reader
, readerRev
-- *** Size
, length
, byteLength
-- ** Folding
, foldl'
, foldr
, byteCmp
, byteEq
-- ** Appending
, splice -- XXX requires MonadIO
-- ** Streams of arrays
-- *** Chunk
-- | Group a stream into arrays.
, chunksOf
, pinnedChunksOf
, buildChunks
-- *** Split
-- | Split an array into slices.
-- *** Concat
-- | Append the arrays in a stream to form a stream of elements.
, concatChunks
, concatChunksRev
-- *** Compact
-- | Append the arrays in a stream to form a stream of larger arrays.
-- ** Deprecated
, unsafeIndex
, bufferChunks

View File

@ -31,33 +31,44 @@ module Streamly.Internal.Data.MutArray.Type
-- ** Type
-- $arrayNotes
MutArray (..)
-- ** Conversion
-- *** Pinned and Unpinned
, pin
, unpin
, isPinned
-- -- * Constructing and Writing
-- ** Casting
, cast
, castUnsafe
, asBytes
, asPtrUnsafe
, asUnpinnedPtrUnsafe
-- ** Construction
, nil
-- *** Uninitialized Arrays
-- *** New
-- | New arrays are always empty arrays with some reserve capacity to
-- extend the length without reallocating.
, new
, newArrayWith
, pinnedNew
, pinnedNewBytes
, pinnedNewAligned
, new
, newArrayWith
-- ** Cloning arrays
-- *** Cloning
, clone
, pinnedClone
-- ** Slicing
-- *** Slicing
-- | Get a subarray without copying
, getSliceUnsafe
, getSlice
, splitAt -- XXX should be able to express using getSlice
, breakOn
-- *** From streams
-- *** Stream Folds
, ArrayUnsafe (..)
, writeNWithUnsafe
, writeNWith
@ -107,10 +118,77 @@ module Streamly.Internal.Data.MutArray.Type
, swapIndices
, unsafeSwapIndices
-- ** Reading
-- *** Indexing
, getIndex
, getIndexUnsafe
, getIndices -- XXX indexReader
, getIndicesWith -- XXX indexReaderWith
-- , getFromThenTo
, getIndexRev
-- *** To Streams
, read
, readRev
, toStreamWith
, toStreamRevWith
, toStreamK
, toStreamKWith
, toStreamKRev
, toStreamKRevWith
-- *** To Containers
, toList
-- *** Unfolds
-- experimental
, producerWith
, producer
, reader
, readerRevWith
, readerRev
-- ** Size and Capacity
-- *** Size
, length
, byteLength
-- *** Capacity
-- , capacity
, byteCapacity
, bytesFree
-- *** Capacity Management
, blockSize
, arrayChunkBytes
, allocBytesToElemCount
, realloc
, resize
, resizeExp
, rightSize
-- ** Folding
, foldl'
, foldr
, byteCmp
, byteEq
-- ** In-place Mutation Algorithms
, strip
, reverse
, permute
, partitionBy
, shuffleBy
, divideBy
, mergeBy
, bubble
-- ** Growing and Shrinking
-- | Arrays grow only at the end, though it is possible to grow on both sides
-- and therefore have a cons as well as snoc. But that will require two
-- bounds in the array representation.
-- | Arrays grow only at the end, though it is possible to grow on both
-- sides and therefore have a cons as well as snoc. But that will require
-- both lower and upper bound in the array representation.
-- *** Appending elements
, snocWith
@ -135,97 +213,32 @@ module Streamly.Internal.Data.MutArray.Type
-- , appendSlice
-- , appendSliceFrom
-- ** Eliminating and Reading
-- *** To streams
, reader
, readerRevWith
, readerRev
-- *** To containers
, toStreamWith
, toStreamRevWith
, toStreamKWith
, toStreamKRevWith
, read
, readRev
, toStreamK
, toStreamKRev
, toList
-- experimental
, producerWith
, producer
-- *** Random reads
, getIndex
, getIndexUnsafe
, getIndices
, getIndicesWith
-- , getFromThenTo
, getIndexRev
-- ** Memory Management
, blockSize
, arrayChunkBytes
, allocBytesToElemCount
, realloc
, resize
, resizeExp
, rightSize
-- ** Size
, length
, byteLength
-- , capacity
, byteCapacity
, bytesFree
-- ** In-place Mutation Algorithms
, strip
, reverse
, permute
, partitionBy
, shuffleBy
, divideBy
, mergeBy
, bubble
-- ** Casting
, cast
, castUnsafe
, asBytes
, asPtrUnsafe
, asUnpinnedPtrUnsafe
-- ** Folding
, foldl'
, foldr
, cmp
, byteCmp
, byteEq
-- Arrays of arrays
-- We can add dimensionality parameter to the array type to get
-- multidimensional arrays. Multidimensional arrays would just be a
-- convenience wrapper on top of single dimensional arrays.
-- ** Streams of Arrays
-- *** Group a stream into arrays
-- *** Chunk
-- | Group a stream into arrays.
, chunksOf
, pinnedChunksOf
, buildChunks
-- *** Split an array into slices
-- *** Split
-- | Split an array into slices.
-- , getSlicesFromLenN
, splitOn
-- , slicesOf
-- *** Flatten a stream of arrays
-- *** Concat
-- | Append the arrays in a stream to form a stream of elements.
, concatChunks
, concatChunksRev
-- *** Compaction
-- *** Compact
-- | Append the arrays in a stream to form a stream of larger arrays.
, SpliceState (..)
, pCompactChunksLE
, rCompactChunksLE
@ -247,6 +260,7 @@ module Streamly.Internal.Data.MutArray.Type
, fromArrayStreamK
, fromStreamDN
, fromStreamD
, cmp
)
where