on master help sign in
Move a few APIs from immutable to mutable array foreign module
commitdc6dc1eba8bbde250647f3228f98c055849164d9 authorAdithya Kumar <adithya@composewell.com> dateMon 26 Jul 2021, 15:03 (5 years ago) parent6157069
2 files changed+51−47
src/Streamly/Internal/Data/Array/Foreign.hs−47 src/Streamly/Internal/Data/Array/Foreign/Mut.hs+51
src/Streamly/Internal/Data/Array/Foreign.hs−47
@@ -100,12 +100,6 @@ module Streamly.Internal.Data.Array.Foreign
100100 -- , findIndex
101101 -- , findIndices
102102
103− -- -- * In-pace mutation (for Mutable Array type)
104− -- , partitionBy
105− -- , shuffleBy
106− -- , foldtWith
107− -- , foldbWith
108−
109103 , unsafeSlice
110104
111105 -- * Immutable Transformations
@@ -370,49 +364,8 @@ splitAt i arr = undefined
370364splice :: Array a -> Array a -> Array a
371365splice arr1 arr2 = undefined
372366
373−-------------------------------------------------------------------------------
374−-- In-place mutation APIs
375−-------------------------------------------------------------------------------
376−
377−-- | Partition an array into two halves using a partitioning predicate. The
378−-- first half retains values where the predicate is 'False' and the second half
379−-- retains values where the predicate is 'True'.
380−{-# INLINE partitionBy #-}
381−partitionBy :: (a -> Bool) -> Array a -> (Array a, Array a)
382−partitionBy f arr = undefined
383−
384−-- | Shuffle corresponding elements from two arrays using a shuffle function.
385−-- If the shuffle function returns 'False' then do nothing otherwise swap the
386−-- elements. This can be used in a bottom up fold to shuffle or reorder the
387−-- elements.
388−shuffleBy :: (a -> a -> m Bool) -> Array a -> Array a -> m (Array a)
389−shuffleBy f arr1 arr2 = undefined
390−
391−-- XXX we can also make the folds partial by stopping at a certain level.
392−--
393−-- | Perform a top down hierarchical recursive partitioning fold of items in
394−-- the container using the given function as the partition function.
395−--
396−-- This will perform a quick sort if the partition function is
397−-- 'partitionBy (< pivot)'.
398−--
399−-- @since 0.7.0
400−{-# INLINABLE foldtWith #-}
401−foldtWith :: Int -> (Array a -> Array a -> m (Array a)) -> Array a -> m (Array a)
402−foldtWith level f = undefined
403−
404−-- | Perform a pairwise bottom up fold recursively merging the pairs. Level
405−-- indicates the level in the tree where the fold would stop.
406−--
407−-- This will perform a random shuffle if the shuffle function is random.
408−-- If we stop at level 0 and repeatedly apply the function then we can do a
409−-- bubble sort.
410−foldbWith :: Int -> (Array a -> Array a -> m (Array a)) -> Array a -> m (Array a)
411−foldbWith level f = undefined
412367-}
413368
414−-- XXX consider the bulk update/accumulation/permutation APIs from vector.
415−
416369-------------------------------------------------------------------------------
417370-- Random reads and writes
418371-------------------------------------------------------------------------------
src/Streamly/Internal/Data/Array/Foreign/Mut.hs+51
@@ -24,6 +24,12 @@ module Streamly.Internal.Data.Array.Foreign.Mut
2424 writeIndex
2525 --, writeIndices
2626 --, writeRanges
27+
28+ -- -- * In-pace mutation (for Mutable Array type)
29+ -- , partitionBy
30+ -- , shuffleBy
31+ -- , foldtWith
32+ -- , foldbWith
2733 )
2834where
2935
@@ -50,3 +56,48 @@ writeIndex arr i a = do
5056 else
5157 liftIO $ unsafeWithForeignPtr (aStart arr) $ \p ->
5258 pokeElemOff p i a
59+
60+{-
61+
62+-------------------------------------------------------------------------------
63+-- In-place mutation APIs
64+-------------------------------------------------------------------------------
65+
66+-- | Partition an array into two halves using a partitioning predicate. The
67+-- first half retains values where the predicate is 'False' and the second half
68+-- retains values where the predicate is 'True'.
69+{-# INLINE partitionBy #-}
70+partitionBy :: (a -> Bool) -> Array a -> (Array a, Array a)
71+partitionBy f arr = undefined
72+
73+-- | Shuffle corresponding elements from two arrays using a shuffle function.
74+-- If the shuffle function returns 'False' then do nothing otherwise swap the
75+-- elements. This can be used in a bottom up fold to shuffle or reorder the
76+-- elements.
77+shuffleBy :: (a -> a -> m Bool) -> Array a -> Array a -> m (Array a)
78+shuffleBy f arr1 arr2 = undefined
79+
80+-- XXX we can also make the folds partial by stopping at a certain level.
81+--
82+-- | Perform a top down hierarchical recursive partitioning fold of items in
83+-- the container using the given function as the partition function.
84+--
85+-- This will perform a quick sort if the partition function is
86+-- 'partitionBy (< pivot)'.
87+--
88+-- @since 0.7.0
89+{-# INLINABLE foldtWith #-}
90+foldtWith :: Int -> (Array a -> Array a -> m (Array a)) -> Array a -> m (Array a)
91+foldtWith level f = undefined
92+
93+-- | Perform a pairwise bottom up fold recursively merging the pairs. Level
94+-- indicates the level in the tree where the fold would stop.
95+--
96+-- This will perform a random shuffle if the shuffle function is random.
97+-- If we stop at level 0 and repeatedly apply the function then we can do a
98+-- bubble sort.
99+foldbWith :: Int -> (Array a -> Array a -> m (Array a)) -> Array a -> m (Array a)
100+foldbWith level f = undefined
101+-}
102+
103+-- XXX consider the bulk update/accumulation/permutation APIs from vector.