primitive-containers 0.5.0 → 0.5.1
raw patch · 9 files changed
+37/−46 lines, 9 filesdep ~primitivedep ~primitive-unlifted
Dependency ranges changed: primitive, primitive-unlifted
Files
- primitive-containers.cabal +4/−4
- src/Data/Map/Internal.hs +13/−13
- src/Data/Map/Lifted/Unlifted.hs +3/−3
- src/Data/Map/Unboxed/Unlifted.hs +5/−5
- src/Data/Map/Unlifted/Lifted.hs +3/−3
- src/Data/Map/Unlifted/Unboxed.hs +3/−3
- src/Data/Set/NonEmpty/Unlifted.hs +3/−4
- src/Data/Set/Unboxed/Internal.hs +0/−7
- src/Data/Set/Unlifted/Internal.hs +3/−4
primitive-containers.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.0 name: primitive-containers-version: 0.5.0+version: 0.5.1 synopsis: containers backed by arrays description: Containers backed by flat arrays. Updates require rebuilding the@@ -39,7 +39,7 @@ , primitive-sort >= 0.1.1 && < 0.2 , hashable >= 1.2.5 , deepseq >= 1.4- , primitive-unlifted >= 0.1 && <0.2+ , primitive-unlifted >= 2.1 && <2.2 if flag(checked) build-depends: contiguous-checked >= 0.4 && < 0.6@@ -91,7 +91,7 @@ , containers >= 0.5.10 , primitive , primitive-containers- , primitive-unlifted >= 0.1.1+ , primitive-unlifted >= 2.1 , quickcheck-classes >= 0.6.2 , tasty , tasty-hunit@@ -110,7 +110,7 @@ build-depends: base >= 4.8 && < 4.12 , primitive- , primitive-unlifted >= 0.1.1+ , primitive-unlifted >= 2.1 , primitive-containers , ghc-prim , gauge
src/Data/Map/Internal.hs view
@@ -244,15 +244,15 @@ return (Map ksFinal vsFinal) -- | /O(n)/ Drop elements for which the predicate returns 'Nothing'.-mapMaybe :: forall karr varr k v w. (ContiguousU karr, Element karr k, ContiguousU varr, Element varr v, Element varr w)+mapMaybe :: forall karr varr varr' k v w. (ContiguousU karr, Element karr k, ContiguousU varr, ContiguousU varr', Element varr v, Element varr' w) => (v -> Maybe w) -> Map karr varr k v- -> Map karr varr k w+ -> Map karr varr' k w {-# INLINE mapMaybe #-} mapMaybe f (Map ks vs) = runST $ do let !sz = I.size vs !(karr :: Mutable karr s k) <- I.new sz- !(varr :: Mutable varr s w) <- I.new sz+ !(varr :: Mutable varr' s w) <- I.new sz let go !ixSrc !ixDst = if ixSrc < sz then do a <- I.indexM vs ixSrc@@ -269,15 +269,15 @@ return (Map ksFinal vsFinal) -- | /O(n)/ Drop elements for which the predicate returns 'Nothing'.-mapMaybeP :: forall karr varr m k v w. (PrimMonad m, ContiguousU karr, Element karr k, ContiguousU varr, Element varr v, Element varr w)+mapMaybeP :: forall karr varr varr' m k v w. (PrimMonad m, ContiguousU karr, Element karr k, ContiguousU varr, ContiguousU varr', Element varr v, Element varr' w) => (v -> m (Maybe w)) -> Map karr varr k v- -> m (Map karr varr k w)+ -> m (Map karr varr' k w) {-# INLINE mapMaybeP #-} mapMaybeP f (Map ks vs) = do let !sz = I.size vs !(karr :: Mutable karr (PrimState m) k) <- I.new sz- !(varr :: Mutable varr (PrimState m) w) <- I.new sz+ !(varr :: Mutable varr' (PrimState m) w) <- I.new sz let go !ixSrc !ixDst = if ixSrc < sz then do a <- I.indexM vs ixSrc@@ -294,15 +294,15 @@ return (Map ksFinal vsFinal) -- | /O(n)/ Drop elements for which the predicate returns 'Nothing'.-mapMaybeWithKey :: forall karr varr k v w. (ContiguousU karr, Element karr k, ContiguousU varr, Element varr v, Element varr w)+mapMaybeWithKey :: forall karr varr varr' k v w. (ContiguousU karr, Element karr k, ContiguousU varr, ContiguousU varr', Element varr v, Element varr' w) => (k -> v -> Maybe w) -> Map karr varr k v- -> Map karr varr k w+ -> Map karr varr' k w {-# INLINEABLE mapMaybeWithKey #-} mapMaybeWithKey f (Map ks vs) = runST $ do let !sz = I.size vs !(karr :: Mutable karr s k) <- I.new sz- !(varr :: Mutable varr s w) <- I.new sz+ !(varr :: Mutable varr' s w) <- I.new sz let go !ixSrc !ixDst = if ixSrc < sz then do k <- I.indexM ks ixSrc@@ -635,18 +635,18 @@ else return accl {-# INLINEABLE foldlMapWithKeyM' #-} -traverse :: (Applicative m, ContiguousU karr, Element karr k, ContiguousU varr, Element varr v, Element varr w)+traverse :: (Applicative m, ContiguousU karr, Element karr k, ContiguousU varr, ContiguousU varr', Element varr v, Element varr' w) => (v -> m w) -> Map karr varr k v- -> m (Map karr varr k w)+ -> m (Map karr varr' k w) {-# INLINEABLE traverse #-} traverse f (Map theKeys theVals) = fmap (Map theKeys) (I.traverse f theVals) -traverseWithKey :: (ContiguousU karr, Element karr k, ContiguousU varr, Element varr v, Element varr v', Applicative f)+traverseWithKey :: (ContiguousU karr, Element karr k, ContiguousU varr, ContiguousU varr', Element varr v, Element varr' v', Applicative f) => (k -> v -> f v') -> Map karr varr k v- -> f (Map karr varr k v')+ -> f (Map karr varr' k v') {-# INLINEABLE traverseWithKey #-} traverseWithKey f (Map theKeys theVals) = fmap (Map theKeys) $ I.itraverse (\i v -> f (I.index theKeys i) v) theVals
src/Data/Map/Lifted/Unlifted.hs view
@@ -42,15 +42,15 @@ import Data.Semigroup (Semigroup) import Data.Primitive (Array)-import Data.Primitive.Unlifted.Array (UnliftedArray)-import Data.Primitive.Unlifted.Class (PrimUnlifted)+import Data.Primitive.Unlifted.Array (UnliftedArray_,UnliftedArray)+import Data.Primitive.Unlifted.Class (PrimUnlifted,Unlifted) import Data.Set.Lifted.Internal (Set(..)) import qualified GHC.Exts as E import qualified Data.Semigroup as SG import qualified Data.Map.Internal as I -- | A map from keys @k@ to values @v@.-newtype Map k v = Map (I.Map Array UnliftedArray k v)+newtype Map k v = Map (I.Map Array (UnliftedArray_ (Unlifted v)) k v) instance (Ord k, Semigroup v, PrimUnlifted v) => Semigroup (Map k v) where Map x <> Map y = Map (I.append x y)
src/Data/Map/Unboxed/Unlifted.hs view
@@ -48,8 +48,8 @@ import Control.Monad.ST (ST) import Data.Primitive (PrimArray,MutablePrimArray) import Data.Primitive.Types (Prim)-import Data.Primitive.Unlifted.Array (UnliftedArray,MutableUnliftedArray)-import Data.Primitive.Unlifted.Class (PrimUnlifted)+import Data.Primitive.Unlifted.Array (UnliftedArray_,UnliftedArray,MutableUnliftedArray)+import Data.Primitive.Unlifted.Class (Unlifted,PrimUnlifted) import Data.Semigroup (Semigroup) import Data.Set.Unboxed.Internal (Set(..)) @@ -58,9 +58,9 @@ import qualified Data.Semigroup as SG import qualified GHC.Exts as E --- | A map from keys @k@ to values @v@. The key type and the value--- type must both have 'Prim' instances.-newtype Map k v = Map (I.Map PrimArray UnliftedArray k v)+-- | A map from keys @k@ to values @v@. The key type must have a+-- 'Prim' instance.+newtype Map k v = Map (I.Map PrimArray (UnliftedArray_ (Unlifted v)) k v) instance (Prim k, Ord k, PrimUnlifted v, Semigroup v) => Semigroup (Map k v) where Map x <> Map y = Map (I.append x y)
src/Data/Map/Unlifted/Lifted.hs view
@@ -39,8 +39,8 @@ import Control.Monad.ST (ST) import Data.Semigroup (Semigroup)-import Data.Primitive.Unlifted.Array (UnliftedArray,MutableUnliftedArray)-import Data.Primitive.Unlifted.Class (PrimUnlifted)+import Data.Primitive.Unlifted.Array (UnliftedArray_,UnliftedArray,MutableUnliftedArray)+import Data.Primitive.Unlifted.Class (PrimUnlifted,Unlifted) import Data.Primitive (Array,MutableArray) import Data.Set.Unlifted.Internal (Set(..)) import qualified GHC.Exts as E@@ -53,7 +53,7 @@ -- -- The data constructor for this type should not be exported. -- I am working on this.-newtype Map k v = Map (I.Map UnliftedArray Array k v)+newtype Map k v = Map (I.Map (UnliftedArray_ (Unlifted k)) Array k v) instance (PrimUnlifted k, Ord k, Semigroup v) => Semigroup (Map k v) where Map x <> Map y = Map (I.append x y)
src/Data/Map/Unlifted/Unboxed.hs view
@@ -39,8 +39,8 @@ import Control.Monad.ST (ST) import Data.Semigroup (Semigroup) import Data.Primitive.Types (Prim)-import Data.Primitive.Unlifted.Array (UnliftedArray,MutableUnliftedArray)-import Data.Primitive.Unlifted.Class (PrimUnlifted)+import Data.Primitive.Unlifted.Array (UnliftedArray_,UnliftedArray,MutableUnliftedArray)+import Data.Primitive.Unlifted.Class (PrimUnlifted,Unlifted) import Data.Primitive.PrimArray (PrimArray,MutablePrimArray) import Data.Set.Unlifted.Internal (Set(..)) import qualified GHC.Exts as E@@ -50,7 +50,7 @@ -- | A map from keys @k@ to values @v@. The key type must have a -- 'PrimUnlifted' instance and the value type must have a 'Prim' -- instance.-newtype Map k v = Map (I.Map UnliftedArray PrimArray k v)+newtype Map k v = Map (I.Map (UnliftedArray_ (Unlifted k)) PrimArray k v) instance (PrimUnlifted k, Ord k, Prim v, Semigroup v) => Semigroup (Map k v) where Map x <> Map y = Map (I.append x y)
src/Data/Set/NonEmpty/Unlifted.hs view
@@ -30,9 +30,8 @@ import Prelude hiding (foldr,foldMap,null) import Data.Hashable (Hashable)-import Data.Primitive.Unlifted.Array (UnliftedArray)-import Data.Primitive.Unlifted.Class (PrimUnlifted)-import Data.Semigroup (Semigroup)+import Data.Primitive.Unlifted.Array (UnliftedArray,UnliftedArray_)+import Data.Primitive.Unlifted.Class (Unlifted,PrimUnlifted) import Data.List.NonEmpty (NonEmpty) import qualified Data.Foldable as F@@ -44,7 +43,7 @@ import qualified Data.Set.Unlifted as S import qualified Data.Set.Unlifted.Internal as SI -newtype Set a = Set (I.Set UnliftedArray a)+newtype Set a = Set (I.Set (UnliftedArray_ (Unlifted a)) a) instance (Ord a, PrimUnlifted a) => Semigroup (Set a) where Set x <> Set y = Set (I.append x y)
src/Data/Set/Unboxed/Internal.hs view
@@ -50,15 +50,8 @@ type Unlifted (Set a) = E.ByteArray# {-# inline toUnlifted# #-} {-# inline fromUnlifted# #-}- {-# inline writeUnliftedArray# #-}- {-# inline readUnliftedArray# #-}- {-# inline indexUnliftedArray# #-} toUnlifted# (Set (I.Set p)) = toUnlifted# p fromUnlifted# b# = Set (I.Set (PrimArray b#))- writeUnliftedArray# a i s = E.writeByteArrayArray# a i (toUnlifted# s)- readUnliftedArray# a i s0 = case E.readByteArrayArray# a i s0 of- (# s1, x #) -> (# s1, fromUnlifted# x #)- indexUnliftedArray# a i = fromUnlifted# (E.indexByteArrayArray# a i) -- | The functions that convert a list to a 'Set' are asymptotically -- better that using @'foldMap' 'singleton'@, with a cost of /O(n*log n)/
src/Data/Set/Unlifted/Internal.hs view
@@ -13,10 +13,9 @@ import Prelude hiding (foldr) import Data.Hashable (Hashable)-import Data.Primitive.Unlifted.Array (UnliftedArray)-import Data.Primitive.Unlifted.Class (PrimUnlifted)+import Data.Primitive.Unlifted.Array (UnliftedArray,UnliftedArray_)+import Data.Primitive.Unlifted.Class (PrimUnlifted,Unlifted) import Data.Primitive (Array)-import Data.Semigroup (Semigroup) import qualified Data.Foldable as F import qualified Data.Hashable as H@@ -24,7 +23,7 @@ import qualified Data.Set.Internal as I import qualified GHC.Exts as E -newtype Set a = Set { getSet :: I.Set UnliftedArray a }+newtype Set a = Set { getSet :: I.Set (UnliftedArray_ (Unlifted a)) a } instance (Ord a, PrimUnlifted a) => Semigroup (Set a) where Set x <> Set y = Set (I.append x y)