Safe Haskell | Trustworthy |
---|---|
Language | Haskell98 |
Saturating maps. These store pure (joinable) values, but when a join fails the map fails (saturates), after which it requires only a small, constant amount of memory.
- class PartialJoinSemiLattice a where
- newtype SatMap k s v = SatMap (LVar s (IORef (SatMapContents k v)) (k, v))
- type SatMapContents k v = Maybe (Map k v, OnSat)
- type OnSat = Par ()
- forEachHP :: Maybe HandlerPool -> SatMap k s v -> (k -> v -> Par d s ()) -> Par d s ()
- newEmptyMap :: Par d s (SatMap k s v)
- newMap :: Map k v -> Par d s (SatMap k s v)
- newFromList :: (Ord k, Eq v) => [(k, v)] -> Par d s (SatMap k s v)
- withCallbacksThenFreeze :: forall k v b s. Eq b => SatMap k s v -> (k -> v -> QPar s ()) -> QPar s b -> QPar s b
- forEach :: SatMap k s v -> (k -> v -> Par d s ()) -> Par d s ()
- insert :: (Ord k, PartialJoinSemiLattice v, Eq v) => k -> v -> SatMap k s v -> Par d s ()
- whenSat :: SatMap k s v -> Par d s () -> Par d s ()
- saturate :: SatMap k s v -> Par d s ()
- fromIMap :: SatMap k Frzn a -> Maybe (Map k a)
- t0 :: SatMap String Frzn Int
- t1 :: SatMap String Frzn Int
Documentation
class PartialJoinSemiLattice a where Source
A partial version of Algebra.Lattice.JoinSemiLattice, this could be made into a complete lattice by the addition of a top element.
The map datatype itself. Like all other LVars, it has an s
parameter (think
STRef
) in addition to the a
parameter that describes the type of elements
in the set.
Performance note: There is only one mutable location in this implementation. Thus it is not a scalable implementation.
SatMap (LVar s (IORef (SatMapContents k v)) (k, v)) |
LVarData1 (SatMap k) | An |
OrderedLVarData1 (SatMap k) | The |
Foldable (SatMap k Trvrsbl) | |
Foldable (SatMap k Frzn) | As with all LVars, after freezing, map elements can be consumed. In
the case of this |
Eq (SatMap k s v) | Equality is physical equality, as with |
(Show k, Show a) => Show (SatMap k Trvrsbl a) | For convenience only; the user could define this. |
(Show k, Show a) => Show (SatMap k Frzn a) | |
DeepFrz a => DeepFrz (SatMap k s a) | |
type FrzType (SatMap k s a) = SatMap k Frzn a |
type SatMapContents k v = Maybe (Map k v, OnSat) Source
:: Maybe HandlerPool | optional pool to enroll in |
-> SatMap k s v | Map to listen to |
-> (k -> v -> Par d s ()) | callback |
-> Par d s () |
Add an (asynchronous) callback that listens for all new key/value pairs added to the map, optionally enrolled in a handler pool.
newEmptyMap :: Par d s (SatMap k s v) Source
Create a fresh map with nothing in it.
withCallbacksThenFreeze :: forall k v b s. Eq b => SatMap k s v -> (k -> v -> QPar s ()) -> QPar s b -> QPar s b Source
Register a per-element callback, then run an action in this context, and freeze when all (recursive) invocations of the callback are complete. Returns the final value of the provided action.
forEach :: SatMap k s v -> (k -> v -> Par d s ()) -> Par d s () Source
Add an (asynchronous) callback that listens for all new new key/value pairs added to the map.
insert :: (Ord k, PartialJoinSemiLattice v, Eq v) => k -> v -> SatMap k s v -> Par d s () Source
Put a single entry into the map. Strict (WHNF) in the key and value.
As with other container LVars, if a key is inserted multiple times, the values had
better be equal (==)
, or a multiple-put error is raised.
whenSat :: SatMap k s v -> Par d s () -> Par d s () Source
Register a callback that is only called if the SatMap LVar becomes saturated.
saturate :: SatMap k s v -> Par d s () Source
Drive the variable to top. This is equivalent to an insert of a conflicting binding.