packages feed

contiguous 0.3.2.0 → 0.3.3.0

raw patch · 2 files changed

+79/−6 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Primitive.Contiguous: foldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m
+ Data.Primitive.Contiguous: freeze :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)
+ Data.Primitive.Contiguous: ifoldl' :: (Contiguous arr, Element arr a) => (b -> Int -> a -> b) -> b -> arr a -> b
+ Data.Primitive.Contiguous: ifoldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (Int -> a -> m) -> arr a -> m
+ Data.Primitive.Contiguous: ifoldlMap1' :: (Contiguous arr, Element arr a, Semigroup m) => (Int -> a -> m) -> arr a -> m

Files

contiguous.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.0 name: contiguous-version: 0.3.2.0+version: 0.3.3.0 homepage: https://github.com/andrewthad/contiguous bug-reports: https://github.com/andrewthad/contiguous/issues author: Andrew Martin
src/Data/Primitive/Contiguous.hs view
@@ -20,8 +20,12 @@   , foldr   , foldMap   , foldl'+  , ifoldl'   , foldr'   , foldMap'+  , foldlMap'+  , ifoldlMap'+  , ifoldlMap1'   , foldlM'   , traverse   , traverseP@@ -40,6 +44,7 @@ import Data.Bits (xor) import Data.Kind (Type) import Data.Primitive+import Data.Semigroup (Semigroup,(<>)) import GHC.Exts (MutableArrayArray#,ArrayArray#,Constraint,sizeofByteArray#,sizeofArray#,sizeofArrayArray#,unsafeCoerce#,sameMutableArrayArray#,isTrue#) import Control.DeepSeq (NFData) @@ -67,6 +72,7 @@   size :: Element arr b => arr b -> Int   sizeMutable :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> m Int   unsafeFreeze :: PrimMonad m => Mutable arr (PrimState m) b -> m (arr b)+  freeze :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)   thaw :: (PrimMonad m, Element arr b) => arr b -> Int -> Int -> m (Mutable arr (PrimState m) b)   copy :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()   copyMutable :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m ()@@ -95,6 +101,7 @@   resize = resizeMutablePrimArray   size = sizeofPrimArray   sizeMutable = getSizeofMutablePrimArray+  freeze = freezePrimArray   unsafeFreeze = unsafeFreezePrimArray   thaw = thawPrimArray   copy = copyPrimArray@@ -139,6 +146,7 @@   resize = resizeArray   size = sizeofArray   sizeMutable = pure . sizeofMutableArray+  freeze = freezeArray   unsafeFreeze = unsafeFreezeArray   thaw = thawArray   copy = copyArray@@ -185,6 +193,7 @@   resize = resizeUnliftedArray   size = sizeofUnliftedArray   sizeMutable = pure . sizeofMutableUnliftedArray+  freeze = freezeUnliftedArray   unsafeFreeze = unsafeFreezeUnliftedArray   thaw = thawUnliftedArray   copy = copyUnliftedArray@@ -221,6 +230,13 @@ errorThunk = error "Contiguous typeclass: unitialized element" {-# NOINLINE errorThunk #-} +freezePrimArray :: (PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> Int -> Int -> m (PrimArray a)+freezePrimArray !src !off !len = do+  dst <- newPrimArray len+  copyMutablePrimArray dst 0 src off len+  unsafeFreezePrimArray dst+{-# INLINE freezePrimArray #-}+ resizeArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> m (MutableArray (PrimState m) a) resizeArray !src !sz = do   dst <- newArray sz errorThunk@@ -290,10 +306,11 @@             go (i+1)   go 0   unsafeFreeze mb-{-# INLINABLE map' #-}+{-# INLINE map' #-}  -- | Right fold over the element of an array. foldr :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b+{-# INLINE foldr #-} foldr f z arr = go 0   where     !sz = size arr@@ -311,8 +328,19 @@       | i == sz = acc       | (# x #) <- index# ary i = go (i+1) (f acc x)   in go 0 z-{-# INLINABLE foldl' #-}+{-# INLINE foldl' #-} +-- | Strict left fold over the elements of an array.+ifoldl' :: (Contiguous arr, Element arr a) => (b -> Int -> a -> b) -> b -> arr a -> b+ifoldl' f !z !ary =+  let+    !sz = size ary+    go !i !acc+      | i == sz = acc+      | (# x #) <- index# ary i = go (i+1) (f acc i x)+  in go 0 z+{-# INLINE ifoldl' #-}+ -- | Strict right fold over the elements of an array. foldr' :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b foldr' f !z !ary =@@ -322,7 +350,7 @@       | (# x #) <- index# ary i       = go (i-1) (f x acc)   in go (size ary - 1) z-{-# INLINABLE foldr' #-}+{-# INLINE foldr' #-}  -- | Monoidal fold over the element of an array. foldMap :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m@@ -333,7 +361,7 @@       | sz > i = case index# arr i of           (# x #) -> mappend (f x) (go (i+1))       | otherwise = mempty-{-# INLINABLE foldMap #-}+{-# INLINE foldMap #-}  -- | Strict monoidal fold over the elements of an array. foldMap' :: (Contiguous arr, Element arr a, Monoid m)@@ -345,8 +373,49 @@       | i == sz = acc       | (# x #) <- index# ary i = go (i+1) (mappend acc (f x))   in go 0 mempty-{-# INLINABLE foldMap' #-}+{-# INLINE foldMap' #-} +-- | Strict left monoidal fold over the elements of an array.+foldlMap' :: (Contiguous arr, Element arr a, Monoid m)+  => (a -> m) -> arr a -> m+foldlMap' f !ary =+  let+    !sz = size ary+    go !i !acc+      | i == sz = acc+      | (# x #) <- index# ary i = go (i+1) (mappend acc (f x))+  in go 0 mempty+{-# INLINE foldlMap' #-}++-- | Strict monoidal fold over the elements of an array.+ifoldlMap' :: (Contiguous arr, Element arr a, Monoid m)+  => (Int -> a -> m)+  -> arr a+  -> m+ifoldlMap' f !ary =+  let+    !sz = size ary+    go !i !acc+      | i == sz = acc+      | (# x #) <- index# ary i = go (i+1) (mappend acc (f i x))+  in go 0 mempty+{-# INLINE ifoldlMap' #-}++-- | Strict monoidal fold over the elements of an array.+ifoldlMap1' :: (Contiguous arr, Element arr a, Semigroup m)+  => (Int -> a -> m)+  -> arr a+  -> m+ifoldlMap1' f !ary =+  let+    !sz = size ary+    go !i !acc+      | i == sz = acc+      | (# x #) <- index# ary i = go (i+1) (acc <> f i x)+    !(# e0 #) = index# ary 0+  in go 1 (f 0 e0)+{-# INLINE ifoldlMap1' #-}+ -- | Strict left monadic fold over the elements of an array. foldlM' :: (Contiguous arr, Element arr a, Monad m) => (b -> a -> m b) -> b -> arr a -> m b foldlM' f z0 arr = go 0 z0@@ -422,6 +491,7 @@         go (ix-1) xs   go (n - 1) l   unsafeFreeze m+{-# INLINE unsafeFromListReverseN #-}  -- | Strictly map over a mutable array, modifying the elements in place. mapMutable' :: (PrimMonad m, Contiguous arr, Element arr a)@@ -439,6 +509,7 @@           write mary i b           go (i + 1)   go 0+{-# INLINE mapMutable' #-}  -- | Strictly map over a mutable array with indices, modifying the elements in place. imapMutable' :: (PrimMonad m, Contiguous arr, Element arr a)@@ -456,6 +527,7 @@           write mary i b           go (i + 1)   go 0+{-# INLINE imapMutable' #-}  traverseP :: (PrimMonad m, Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b)   => (a -> m b)@@ -474,6 +546,7 @@   in do       mary <- new sz       go 0 mary+{-# INLINE traverseP #-}  newtype STA v a = STA {_runSTA :: forall s. Mutable v s a -> ST s (v a)}