packages feed

primitive-extras 0.8 → 0.8.1

raw patch · 4 files changed

+34/−2 lines, 4 files

Files

library/PrimitiveExtras/SmallArray.hs view
@@ -70,6 +70,29 @@       copySmallArray newMa nextIndex array index amountOfFollowingElements       return newMa +{-# INLINE update #-}+update :: (a -> a) -> Int -> SmallArray a -> SmallArray a+update fn index array =+  let+    size = sizeofSmallArray array+    in if size > index && index >= 0+      then unsafeUpdateWithSize fn index size array+      else array++{-# INLINE unsafeUpdate #-}+unsafeUpdate :: (a -> a) -> Int -> SmallArray a -> SmallArray a+unsafeUpdate fn index array =+  unsafeUpdateWithSize fn index (sizeofSmallArray array) array++{-# INLINE unsafeUpdateWithSize #-}+unsafeUpdateWithSize :: (a -> a) -> Int -> Int -> SmallArray a -> SmallArray a+unsafeUpdateWithSize fn index size array =+  runST $ do+    m <- thawSmallArray array 0 size+    element <- readSmallArray m index+    writeSmallArray m index $! fn element+    unsafeFreezeSmallArray m+ {-# INLINE cons #-} cons :: a -> SmallArray a -> SmallArray a cons a array =
library/PrimitiveExtras/SparseSmallArray.hs view
@@ -89,6 +89,15 @@     sparseIndex = Bitmap.populatedIndex i b     in SparseSmallArray b (SmallArray.set sparseIndex e a) +{-# INLINE update #-}+update :: (e -> e) -> Int -> SparseSmallArray e -> SparseSmallArray e+update fn i (SparseSmallArray b a) =+  let+    sparseIndex = Bitmap.populatedIndex i b+    in+      SparseSmallArray b+        (SmallArray.unsafeUpdate fn sparseIndex a)+ -- | -- Remove an element. {-# INLINE unset #-}
library/PrimitiveExtras/Types.hs view
@@ -10,7 +10,7 @@ An immutable space-efficient sparse array,  which can only store not more than 32 or 64 elements depending on the system architecure. -}-data SparseSmallArray e = SparseSmallArray !Bitmap !(SmallArray e)+data SparseSmallArray e = SparseSmallArray {-# UNPACK #-} !Bitmap {-# UNPACK #-} !(SmallArray e)  {-| A word-size set of ints.
primitive-extras.cabal view
@@ -1,5 +1,5 @@ name: primitive-extras-version: 0.8+version: 0.8.1 category: Primitive synopsis: Extras for the "primitive" library homepage: https://github.com/metrix-ai/primitive-extras