monoidmap-examples 0.1.0.0 → 0.1.0.1
raw patch · 3 files changed
+31/−1 lines, 3 files
Files
- CHANGELOG.md +5/−0
- components/monoidmap-examples/Data/MonoidMap/Examples/RecoveredMap.hs +21/−0
- monoidmap-examples.cabal +5/−1
CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.1.0.1++- Revised the inlining of functions exported by `RecoveredMap`, so that GHC can+ specialise them at call sites.+ # 0.1.0.0 - Changed the role of the value type parameter of `NestedMonoidMap` from
components/monoidmap-examples/Data/MonoidMap/Examples/RecoveredMap.hs view
@@ -60,60 +60,79 @@ instance Ord k => Semigroup (Map k v) where (<>) = coerce @(MonoidMap k (First v) -> _ -> _) (<>)+ {-# INLINE (<>) #-} stimes = stimesIdempotentMonoid+ {-# INLINE stimes #-} instance (Show k, Show v) => Show (Map k v) where show = ("fromList " <>) . show . toList+ {-# INLINE show #-} instance Functor (Map k) where fmap = map+ {-# INLINE fmap #-} empty :: Map k v empty = Map MonoidMap.empty+{-# INLINE empty #-} singleton :: Ord k => k -> v -> Map k v singleton k = Map . MonoidMap.singleton k . pure+{-# INLINE singleton #-} fromList :: Ord k => [(k, v)] -> Map k v fromList = Map . MonoidMap.fromListWith (const id) . fmap (fmap pure)+{-# INLINE fromList #-} toList :: Map k v -> [(k, v)] toList = mapMaybe (getFirst . sequenceA) . MonoidMap.toList . unMap+{-# INLINE toList #-} delete :: Ord k => k -> Map k v -> Map k v delete k = Map . MonoidMap.nullify k . unMap+{-# INLINE delete #-} insert :: Ord k => k -> v -> Map k v -> Map k v insert k v = Map . MonoidMap.set k (pure v) . unMap+{-# INLINE insert #-} keysSet :: Map k v -> Set k keysSet = MonoidMap.nonNullKeys . unMap+{-# INLINE keysSet #-} lookup :: Ord k => k -> Map k v -> Maybe v lookup k = getFirst . MonoidMap.get k . unMap+{-# INLINE lookup #-} member :: Ord k => k -> Map k v -> Bool member k = MonoidMap.nonNullKey k . unMap+{-# INLINE member #-} map :: (v1 -> v2) -> Map k v1 -> Map k v2 map f = Map . MonoidMap.map (fmap f) . unMap+{-# INLINE map #-} mapWithKey :: (k -> v1 -> v2) -> Map k v1 -> Map k v2 mapWithKey f = Map . MonoidMap.mapWithKey (fmap . f) . unMap+{-# INLINE mapWithKey #-} mapAccumL :: (s -> v1 -> (s, v2)) -> s -> Map k v1 -> (s, Map k v2) mapAccumL f s m = Map <$> MonoidMap.mapAccumL (accum f) s (unMap m)+{-# INLINE mapAccumL #-} mapAccumR :: (s -> v1 -> (s, v2)) -> s -> Map k v1 -> (s, Map k v2) mapAccumR f s m = Map <$> MonoidMap.mapAccumR (accum f) s (unMap m)+{-# INLINE mapAccumR #-} mapAccumLWithKey :: (s -> k -> v1 -> (s, v2)) -> s -> Map k v1 -> (s, Map k v2) mapAccumLWithKey f s m = Map <$> MonoidMap.mapAccumLWithKey (accumWithKey f) s (unMap m)+{-# INLINE mapAccumLWithKey #-} mapAccumRWithKey :: (s -> k -> v1 -> (s, v2)) -> s -> Map k v1 -> (s, Map k v2) mapAccumRWithKey f s m = Map <$> MonoidMap.mapAccumRWithKey (accumWithKey f) s (unMap m)+{-# INLINE mapAccumRWithKey #-} -------------------------------------------------------------------------------- -- Utilities@@ -123,8 +142,10 @@ accum f s1 (First mv1) = case mv1 of Just v1 -> let (s2, v2) = f s1 v1 in (s2, First (Just v2)) Nothing -> (s1, First Nothing)+{-# INLINE accum #-} accumWithKey :: (s -> k -> v1 -> (s, v2)) -> s -> k -> First v1 -> (s, First v2) accumWithKey f s1 k (First mv1) = case mv1 of Just v1 -> let (s2, v2) = f s1 k v1 in (s2, First (Just v2)) Nothing -> (s1, First Nothing)+{-# INLINE accumWithKey #-}
monoidmap-examples.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: monoidmap-examples-version: 0.1.0.0+version: 0.1.0.1 homepage: https://github.com/jonathanknowles/monoidmap/tree/HEAD/packages/monoidmap-examples bug-reports: https://github.com/jonathanknowles/monoidmap/issues license: Apache-2.0@@ -108,6 +108,10 @@ -- Report allocation and memory statistics for each benchmark: ghc-options: "-with-rtsopts=-T"+ -- Align functions to cache lines, so that results are not skewed by+ -- incidental changes in code alignment:+ ghc-options:+ -fproc-alignment=64 test-suite monoidmap-examples-test import: