on master help sign in
Move writeIndex to Internal.Data.Array.Foreign.Mut module
67062eeAdithya Kumar
src/Streamly/Internal/Data/Array/Foreign.hs−32
@@ -93,21 +93,6 @@ module Streamly.Internal.Data.Array.Foreign
93 -- , readChunksOfFrom
93 -- , readChunksOfFrom
94 -- , ...
94 -- , ...
95
95
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−
111 -- -- * Search
96 -- -- * Search
112 -- , bsearch
97 -- , bsearch
113 -- , bsearchIndex
98 -- , bsearchIndex
@@ -465,23 +450,6 @@ readSliceRev :: (IsStream t, Monad m, Storable a)
465readSliceRev arr i len = undefined
450readSliceRev arr i len = undefined
466-}
451-}
467
452
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−
485{-
453{-
486-- | @writeSlice arr i count stream@ writes a stream to the array @arr@
454-- | @writeSlice arr i count stream@ writes a stream to the array @arr@
487-- starting at index @i@ and writing up to @count@ elements in the forward
455-- 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
399 -- streamly-core-array
399 -- streamly-core-array
400 -- May depend on streamly-core-stream
400 -- May depend on streamly-core-stream
401 , Streamly.Internal.Data.Array.Foreign.Mut.Type
401 , Streamly.Internal.Data.Array.Foreign.Mut.Type
402+ , Streamly.Internal.Data.Array.Foreign.Mut
402 , Streamly.Internal.Data.Array.Foreign.Type
403 , Streamly.Internal.Data.Array.Foreign.Type
403 , Streamly.Internal.Data.Array.Prim.Mut.Type
404 , Streamly.Internal.Data.Array.Prim.Mut.Type
404 , Streamly.Internal.Data.Array.Prim.Type
405 , Streamly.Internal.Data.Array.Prim.Type