packages feed

stm-containers 0.2.10 → 0.2.11

raw patch · 11 files changed

+83/−46 lines, 11 filesdep ~base

Dependency ranges changed: base

Files

executables/APITests/MapTests.hs view
@@ -72,6 +72,20 @@ -- * Tests ------------------------- +prop_sizeAndList =+  forAll gen prop+  where+    gen = do+      keys <- nub <$> listOf (arbitrary :: Gen Char)+      mapM (liftA2 (flip (,)) (arbitrary :: Gen Int) . pure) keys+    prop list =+      length list == stmMapLength+      where+        stmMapLength =+          unsafePerformIO $ atomically $ do+            x <- stmMapFromList list+            STMMap.size x+ prop_fromListToListIsomorphism =   forAll gen prop   where
executables/ConcurrentInsertionBench.hs view
@@ -119,12 +119,12 @@           [             bgroup "STM Containers"               [-                bench "Focus-based" $ +                bench "Focus-based" $ nfIO $                   scSessionRunner focusSCInterpreter threadTransactions,-                bench "Specialized" $ +                bench "Specialized" $ nfIO $                   scSessionRunner specializedSCInterpreter threadTransactions               ],-            bench "Unordered Containers" $+            bench "Unordered Containers" $ nfIO $               ucSessionRunner threadTransactions           ]   where
executables/ConcurrentTransactionsBench.hs view
@@ -202,7 +202,7 @@         map concat $!          slices (length transactionsGroups `div` threadsNum) transactionsGroups       in-        bench (shows threadsNum . showString "/" . shows (transactionsNum `div` threadsNum) $ "") $+        bench (shows threadsNum . showString "/" . shows (transactionsNum `div` threadsNum) $ "") $ nfIO $           scSessionRunner specializedSCInterpreter session   where     threadsNums = [1, 2, 4, 6, 8, 12, 16, 32, 40, 52, 64, 80, 128]
executables/InsertionBench.hs view
@@ -16,12 +16,12 @@     [       bgroup "STM Containers"       [-        bench "focus-based" $ +        bench "focus-based" $ nfIO $           do             t <- atomically $ STMContainers.new :: IO (STMContainers.Map Text.Text ())             forM_ keys $ \k -> atomically $ STMContainers.focus (Focus.insertM ()) k t         ,-        bench "specialized" $+        bench "specialized" $ nfIO $           do             t <- atomically $ STMContainers.new :: IO (STMContainers.Map Text.Text ())             forM_ keys $ \k -> atomically $ STMContainers.insert () k t@@ -33,7 +33,7 @@       bench "Containers" $         nf (foldr (\k -> Containers.insert k ()) Containers.empty) keys       ,-      bench "Hashtables" $ +      bench "Hashtables" $ nfIO $         do           t <- Hashtables.new :: IO (Hashtables.BasicHashTable Text.Text ())           forM_ keys $ \k -> Hashtables.insert t k ()
library/STMContainers/Bimap.hs view
@@ -14,6 +14,7 @@   focus1,   focus2,   null,+  size,   stream, ) where@@ -61,6 +62,12 @@ {-# INLINABLE null #-} null :: Bimap a b -> STM Bool null = Map.null . m1++-- |+-- Get the number of elements.+{-# INLINE size #-}+size :: Bimap a b -> STM Int+size = Map.size . m1  -- | -- Look up a right value by a left value.
library/STMContainers/HAMT/Nodes.hs view
@@ -159,3 +159,17 @@     Nodes n -> stream (Level.succ l) n     Leaf _ e -> return e     Leaves _ a -> ListT.fromFoldable a++size :: Nodes e -> STM Int+size nodes =+  readTVar nodes >>= foldlM step 0+  where+    step a =+      fmap (a+) . nodeSize+      where+        nodeSize :: Node e -> STM Int+        nodeSize =+          \case+            Nodes nodes -> size nodes+            Leaf _ _ -> pure 1+            Leaves _ x -> pure (SizedArray.size x)
library/STMContainers/Map.hs view
@@ -9,6 +9,7 @@   lookup,   focus,   null,+  size,   stream, ) where@@ -87,6 +88,12 @@ {-# INLINE null #-} null :: Map k v -> STM Bool null (Map h) = HAMT.null h++-- |+-- Get the number of elements.+{-# INLINE size #-}+size :: Map k v -> STM Int+size (Map h) = HAMTNodes.size h  -- | -- Stream associations.
library/STMContainers/Multimap.hs view
@@ -10,6 +10,7 @@   delete,   deleteByKey,   lookup,+  lookupByKey,   focus,   null,   stream,@@ -26,7 +27,7 @@  -- | -- A multimap, based on an STM-specialized hash array mapped trie.--- +-- -- Basically it's just a wrapper API around @'Map.Map' k ('Set.Set' v)@. newtype Multimap k v = Multimap (Map.Map k (Set.Set v))   deriving (Typeable)@@ -47,19 +48,25 @@ -- Look up an item by a value and a key. {-# INLINE lookup #-} lookup :: (Association k v) => v -> k -> Multimap k v -> STM Bool-lookup v k (Multimap m) = +lookup v k (Multimap m) =   maybe (return False) (Set.lookup v) =<< Map.lookup k m  -- |+-- Look up all values by key.+{-# INLINE lookupByKey #-}+lookupByKey :: Key k => k -> Multimap k v -> STM (Maybe (Set.Set v))+lookupByKey k (Multimap m) = Map.lookup k m++-- | -- Insert an item. {-# INLINABLE insert #-} insert :: (Association k v) => v -> k -> Multimap k v -> STM () insert v k (Multimap m) =   Map.focus ms k m   where-    ms = -      \case -        Just s -> +    ms =+      \case+        Just s ->           do             Set.insert v s             return ((), Focus.Keep)@@ -76,9 +83,9 @@ delete v k (Multimap m) =   Map.focus ms k m   where-    ms = -      \case -        Just s -> +    ms =+      \case+        Just s ->           do             Set.delete v s             Set.null s >>= returnDecision . bool Focus.Keep Focus.Remove@@ -91,23 +98,23 @@ -- Delete all values associated with a key. {-# INLINEABLE deleteByKey #-} deleteByKey :: Key k => k -> Multimap k v -> STM ()-deleteByKey k (Multimap m) = +deleteByKey k (Multimap m) =   Map.delete k m  -- | -- Focus on an item with a strategy by a value and a key.--- +-- -- This function allows to perform simultaneous lookup and modification.--- +-- -- The strategy is over a unit since we already know, -- which value we're focusing on and it doesn't make sense to replace it, -- however we still can decide wether to keep or remove it. {-# INLINE focus #-} focus :: (Association k v) => Focus.StrategyM STM () r -> v -> k -> Multimap k v -> STM r-focus = +focus =   \s v k (Multimap m) -> Map.focus (liftSetItemStrategy v s) k m   where-    liftSetItemStrategy :: +    liftSetItemStrategy ::       (Set.Element e) => e -> Focus.StrategyM STM () r -> Focus.StrategyM STM (Set.Set e) r     liftSetItemStrategy e s =       \case@@ -123,7 +130,7 @@                     return (Focus.Replace s)                 _ ->                   return Focus.Keep-        Just set -> +        Just set ->           do             r <- Set.focus s e set             (r,) . bool Focus.Keep Focus.Remove <$> Set.null set@@ -136,8 +143,8 @@  -- | -- Construct a new multimap in IO.--- --- This is useful for creating it on a top-level using 'unsafePerformIO', +--+-- This is useful for creating it on a top-level using 'unsafePerformIO', -- because using 'atomically' inside 'unsafePerformIO' isn't possible. {-# INLINE newIO #-} newIO :: IO (Multimap k v)@@ -151,11 +158,11 @@  -- | -- Stream associations.--- --- Amongst other features this function provides an interface to folding +--+-- Amongst other features this function provides an interface to folding -- via the 'ListT.fold' function. stream :: Multimap k v -> ListT STM (k, v)-stream (Multimap m) = +stream (Multimap m) =   Map.stream m >>= \(k, s) -> (k,) <$> Set.stream s  -- |
library/STMContainers/Prelude.hs view
@@ -1,8 +1,6 @@ module STMContainers.Prelude (    module Exports,-  bug,-  bottom,   traversePair, ) where@@ -11,10 +9,6 @@ ------------------------- import BasePrelude as Exports --- placeholders---------------------------import Development.Placeholders as Exports- -- hashable ------------------------- import Data.Hashable as Exports (Hashable(..))@@ -26,16 +20,6 @@ -- list-t ------------------------- import ListT as Exports (ListT)---- custom---------------------------import qualified Debug.Trace.LocationTH--bug = [e| $(Debug.Trace.LocationTH.failure) . (msg <>) |]-  where-    msg = "A \"stm-containers\" package bug: " :: String--bottom = [e| $bug "Bottom evaluated" |]  -- | A replacement for the missing 'Traverse' instance of pair in base < 4.7. traversePair :: Functor f => (a -> f b) -> (c, a) -> f (c, b)
library/STMContainers/Set.hs view
@@ -9,6 +9,7 @@   lookup,   focus,   null,+  size,   stream, ) where@@ -91,6 +92,12 @@ {-# INLINE null #-} null :: Set e -> STM Bool null = HAMT.null . hamt++-- |+-- Get the number of elements.+{-# INLINE size #-}+size :: Set e -> STM Int+size (Set h) = HAMTNodes.size h  -- | -- Stream elements.
stm-containers.cabal view
@@ -1,7 +1,7 @@ name:   stm-containers version:-  0.2.10+  0.2.11 synopsis:   Containers for STM description:@@ -66,9 +66,6 @@     list-t >= 0.2 && < 0.5,     focus >= 0.1.2 && < 0.2,     transformers >= 0.2 && < 0.6,-    -- debugging:-    loch-th == 0.2.*,-    placeholders == 0.1.*,     -- general:     primitive >= 0.5 && < 0.7,     base-prelude < 2