packages feed

stm-containers 0.1.4 → 0.2.0

raw patch · 8 files changed

+83/−41 lines, 8 filesdep +list-tdep +transformersdep ~HTFdep ~focus

Dependencies added: list-t, transformers

Dependency ranges changed: HTF, focus

Files

library/STMContainers/Bimap.hs view
@@ -12,8 +12,8 @@   lookup2,   focus1,   focus2,-  foldM,   null,+  stream, ) where @@ -137,7 +137,10 @@ focus2 s b (Bimap m1 m2) = (inline focus1) s b (Bimap m2 m1)  -- |--- Fold all the associations.-{-# INLINABLE foldM #-}-foldM :: (r -> (a, b) -> STM r) -> r -> Bimap a b -> STM r-foldM s r = Map.foldM s r . m1+-- Stream associations.+-- +-- Amongst other features this function provides an interface to folding +-- via the 'ListT.fold' function.+{-# INLINE stream #-}+stream :: Bimap a b -> ListT STM (a, b)+stream = Map.stream . m1
library/STMContainers/HAMT.hs view
@@ -32,3 +32,7 @@ {-# INLINE null #-} null :: HAMT e -> STM Bool null = Nodes.null++{-# INLINE stream #-}+stream :: HAMT e -> ListT STM e+stream = Nodes.stream 0
library/STMContainers/HAMT/Nodes.hs view
@@ -6,6 +6,7 @@ import qualified STMContainers.SizedArray as SizedArray import qualified STMContainers.HAMT.Level as Level import qualified Focus+import qualified ListT   type Nodes e = TVar (WordArray.WordArray (Node e))@@ -151,3 +152,10 @@       Nodes ns -> foldM step acc' (Level.succ level) ns       Leaf _ e -> step acc' e       Leaves _ a -> SizedArray.foldM step acc' a++stream :: Level.Level -> Nodes e -> ListT.ListT STM e+stream l =+  lift . readTVar >=> ListT.fromFoldable >=> \case+    Nodes n -> stream (Level.succ l) n+    Leaf _ e -> return e+    Leaves _ a -> ListT.fromFoldable a
library/STMContainers/Map.hs view
@@ -8,8 +8,8 @@   delete,   lookup,   focus,-  foldM,   null,+  stream, ) where @@ -71,12 +71,6 @@     f' = (fmap . fmap . fmap) (\v -> k `seq` v `seq` (k, v)) . f . fmap associationValue  -- |--- Fold all the items of a map.-{-# INLINE foldM #-}-foldM :: (a -> (k, v) -> STM a) -> a -> Map k v -> STM a-foldM s a (Map h) = HAMT.foldM s a h---- | -- Construct a new map. {-# INLINE new #-} new :: STM (Map k v)@@ -96,3 +90,12 @@ {-# INLINE null #-} null :: Map k v -> STM Bool null (Map h) = HAMT.null h++-- |+-- Stream associations.+-- +-- Amongst other features this function provides an interface to folding +-- via the 'ListT.fold' function.+{-# INLINE stream #-}+stream :: Map k v -> ListT STM (k, v)+stream (Map h) = HAMT.stream h
library/STMContainers/Multimap.hs view
@@ -8,8 +8,9 @@   delete,   lookup,   focus,-  foldM,   null,+  stream,+  streamByKey, ) where @@ -108,18 +109,6 @@             (r,) . bool Focus.Keep Focus.Remove <$> Set.null set  -- |--- Fold all the items.-{-# INLINE foldM #-}-foldM :: (a -> (k, v) -> STM a) -> a -> Multimap k v -> STM a-foldM f a (Multimap m) = -  Map.foldM f' a m-  where-    f' a' (k, set) = -      Set.foldM f'' a' set-      where-        f'' a'' v = f a'' (k, v)---- | -- Construct a new multimap. {-# INLINE new #-} new :: STM (Multimap k v)@@ -139,3 +128,20 @@ {-# INLINE null #-} null :: Multimap k v -> STM Bool null (Multimap m) = Map.null m++-- |+-- Stream associations.+-- +-- 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) = +  Map.stream m >>= \(k, s) -> (k,) <$> Set.stream s++-- |+-- Stream values by a key.+streamByKey :: Association k v => k -> Multimap k v -> ListT STM v+streamByKey k (Multimap m) =+  lift (Map.lookup k m) >>= maybe mempty Set.stream++
library/STMContainers/Prelude.hs view
@@ -19,6 +19,14 @@ ------------------------- import Data.Hashable as Exports (Hashable(..)) +-- transformers+-------------------------+import Control.Monad.Trans.Class as Exports++-- list-t+-------------------------+import ListT as Exports (ListT)+ -- custom ------------------------- import qualified Debug.Trace.LocationTH
library/STMContainers/Set.hs view
@@ -8,8 +8,8 @@   delete,   lookup,   focus,-  foldM,   null,+  stream, ) where @@ -71,12 +71,6 @@       (fmap . fmap . fmap) (const (HAMTElement e)) . s . fmap (const ())  -- |--- Fold all the elements.-{-# INLINE foldM #-}-foldM :: (a -> e -> STM a) -> a -> Set e -> STM a-foldM f a = HAMT.foldM (\a -> f a . elementValue) a . hamt---- | -- Construct a new set. {-# INLINE new #-} new :: STM (Set e)@@ -96,3 +90,12 @@ {-# INLINE null #-} null :: Set e -> STM Bool null = HAMT.null . hamt++-- |+-- Stream elements.+-- +-- Amongst other features this function provides an interface to folding +-- via the 'ListT.fold' function.+{-# INLINE stream #-}+stream :: Set e -> ListT STM e+stream = fmap elementValue . HAMT.stream . hamt
stm-containers.cabal view
@@ -1,7 +1,7 @@ name:   stm-containers version:-  0.1.4+  0.2.0 synopsis:   Containers for STM description:@@ -63,7 +63,9 @@     -- data:     hashable < 1.3,     -- control:-    focus > 0.1.0 && < 0.2,+    list-t >= 0.2.4 && < 0.3,+    focus >= 0.1.2 && < 0.2,+    transformers >= 0.3 && < 0.5,     -- debugging:     loch-th == 0.2.*,     placeholders == 0.1.*,@@ -89,11 +91,12 @@     free >= 4.6 && < 4.10,     mtl == 2.*,     QuickCheck == 2.7.*,-    HTF == 0.11.*,+    HTF == 0.12.*,     -- data:     hashable < 1.3,     -- control:-    focus > 0.1.0 && < 0.2,+    list-t >= 0.2.4 && < 0.3,+    focus >= 0.1.2 && < 0.2,     -- debugging:     loch-th == 0.2.*,     placeholders == 0.1.*,@@ -115,14 +118,15 @@     APITests.hs   build-depends:     QuickCheck == 2.7.*,-    HTF == 0.11.*,+    HTF == 0.12.*,     stm-containers,     -- debugging:     loch-th == 0.2.*,     placeholders == 0.1.*,     -- general:     base-prelude == 0.1.*,-    focus > 0.1.0 && < 0.2,+    list-t >= 0.2.4 && < 0.3,+    focus >= 0.1.2 && < 0.2,     unordered-containers == 0.2.*,     free >= 4.6 && < 4.10,     mtl == 2.*,@@ -153,7 +157,8 @@     criterion == 0.8.*,     -- data:     text < 1.2,-    focus > 0.1.0 && < 0.2,+    list-t >= 0.2.4 && < 0.3,+    focus >= 0.1.2 && < 0.2,     hashable < 1.3,     hashtables == 1.1.*,     containers == 0.5.*,@@ -185,7 +190,8 @@     mwc-random-monad == 0.7.*,     -- data:     text < 1.2,-    focus > 0.1.0 && < 0.2,+    list-t >= 0.2.4 && < 0.3,+    focus >= 0.1.2 && < 0.2,     unordered-containers == 0.2.*,     hashable < 1.3,     stm-containers,@@ -218,7 +224,8 @@     -- data:     containers >= 0.5.2 && < 0.6,     text < 1.2,-    focus > 0.1.0 && < 0.2,+    list-t >= 0.2.4 && < 0.3,+    focus >= 0.1.2 && < 0.2,     unordered-containers == 0.2.*,     hashable < 1.3,     stm-containers,