on master help sign in
Move writeIndex to Internal.Data.Array.Foreign.Mut module
commit67062eeae81c2aa11c9bad31f957ed7db0ae0d63 authorAdithya Kumar <adithya@composewell.com> dateTue 20 Jul 2021, 03:16 (5 years ago) parent097a171
3 files changed+53−32
src/Streamly/Internal/Data/Array/Foreign.hs−32 src/Streamly/Internal/Data/Array/Foreign/Mut.hs+52 streamly.cabal+1
src/Streamly/Internal/Data/Array/Foreign.hs−32
@@ -93,21 +93,6 @@ module Streamly.Internal.Data.Array.Foreign
9393 -- , readChunksOfFrom
9494 -- , ...
9595
96− -- , writeIndex
97− -- , writeFrom -- start writing at the given position
98− -- , writeFromRev
99− -- , writeTo -- write from beginning up to the given position
100− -- , writeToRev
101− -- , writeFromTo
102− -- , writeFromThenTo
103− --
104− -- , writeChunksOfFrom
105− -- , ...
106−
107− , writeIndex
108− --, writeIndices
109− --, writeRanges
110−
11196 -- -- * Search
11297 -- , bsearch
11398 -- , bsearchIndex
@@ -465,23 +450,6 @@ readSliceRev :: (IsStream t, Monad m, Storable a)
465450readSliceRev arr i len = undefined
466451-}
467452
468−-- | /O(1)/ Write the given element at the given index in the array.
469−-- Performs in-place mutation of the array.
470−--
471−-- /Pre-release/
472−{-# INLINE writeIndex #-}
473−writeIndex :: (MonadIO m, Storable a) => Array a -> Int -> a -> m ()
474−writeIndex arr i a = do
475− let maxIndex = length arr - 1
476− if i < 0
477− then error "writeIndex: negative array index"
478− else if i > maxIndex
479− then error $ "writeIndex: specified array index " ++ show i
480− ++ " is beyond the maximum index " ++ show maxIndex
481− else
482− liftIO $ unsafeWithForeignPtr (aStart arr) $ \p ->
483− pokeElemOff p i a
484−
485453{-
486454-- | @writeSlice arr i count stream@ writes a stream to the array @arr@
487455-- starting at index @i@ and writing up to @count@ elements in the forward
src/Streamly/Internal/Data/Array/Foreign/Mut.hsnew file+52
@@ -0,0 +1,52 @@
1+#include "inline.hs"
2+
3+-- |
4+-- Module : Streamly.Internal.Data.Array.Foreign.Mut
5+-- Copyright : (c) 2020 Composewell Technologies
6+-- License : BSD-3-Clause
7+-- Maintainer : streamly@composewell.com
8+-- Stability : experimental
9+-- Portability : GHC
10+--
11+module Streamly.Internal.Data.Array.Foreign.Mut
12+ (
13+ -- , writeIndex
14+ -- , writeFrom -- start writing at the given position
15+ -- , writeFromRev
16+ -- , writeTo -- write from beginning up to the given position
17+ -- , writeToRev
18+ -- , writeFromTo
19+ -- , writeFromThenTo
20+ --
21+ -- , writeChunksOfFrom
22+ -- , ...
23+
24+ writeIndex
25+ --, writeIndices
26+ --, writeRanges
27+ )
28+where
29+
30+import Control.Monad.IO.Class (MonadIO(..))
31+import Foreign.Storable (Storable(..))
32+import Streamly.Internal.BaseCompat (unsafeWithForeignPtr)
33+
34+import Prelude hiding (length)
35+import Streamly.Internal.Data.Array.Foreign.Mut.Type
36+
37+-- | /O(1)/ Write the given element at the given index in the array.
38+-- Performs in-place mutation of the array.
39+--
40+-- /Pre-release/
41+{-# INLINE writeIndex #-}
42+writeIndex :: (MonadIO m, Storable a) => Array a -> Int -> a -> m ()
43+writeIndex arr i a = do
44+ let maxIndex = length arr - 1
45+ if i < 0
46+ then error "writeIndex: negative array index"
47+ else if i > maxIndex
48+ then error $ "writeIndex: specified array index " ++ show i
49+ ++ " is beyond the maximum index " ++ show maxIndex
50+ else
51+ liftIO $ unsafeWithForeignPtr (aStart arr) $ \p ->
52+ pokeElemOff p i a
streamly.cabal+1
@@ -399,6 +399,7 @@ library
399399 -- streamly-core-array
400400 -- May depend on streamly-core-stream
401401 , Streamly.Internal.Data.Array.Foreign.Mut.Type
402+ , Streamly.Internal.Data.Array.Foreign.Mut
402403 , Streamly.Internal.Data.Array.Foreign.Type
403404 , Streamly.Internal.Data.Array.Prim.Mut.Type
404405 , Streamly.Internal.Data.Array.Prim.Type