Safe Haskell | Trustworthy |
---|

This module provides sets that only grow. It is based on a
*concurrent skip list* representation of sets.

This module is usually a more efficient alternative to Data.LVar.PureSet, and provides almost the same interface. However, it's always good to test multiple data structures if you have a performance-critical use case.

- data ISet s a
- newEmptySet :: Ord a => Par d s (ISet s a)
- newSet :: Ord a => Set a -> Par d s (ISet s a)
- newFromList :: Ord a => [a] -> Par d s (ISet s a)
- insert :: Ord a => a -> ISet s a -> Par d s ()
- waitElem :: Ord a => a -> ISet s a -> Par d s ()
- waitSize :: Int -> ISet s a -> Par d s ()
- member :: a -> ISet Frzn a -> Bool
- forEach :: ISet s a -> (a -> Par d s ()) -> Par d s ()
- forEachHP :: Maybe HandlerPool -> ISet s a -> (a -> Par d s ()) -> Par d s ()
- freezeSetAfter :: ISet s a -> (a -> QPar s ()) -> QPar s ()
- withCallbacksThenFreeze :: Eq b => ISet s a -> (a -> QPar s ()) -> QPar s b -> QPar s b
- copy :: Ord a => ISet s a -> Par d s (ISet s a)
- traverseSet :: Ord b => (a -> Par d s b) -> ISet s a -> Par d s (ISet s b)
- traverseSet_ :: Ord b => (a -> Par d s b) -> ISet s a -> ISet s b -> Par d s ()
- union :: Ord a => ISet s a -> ISet s a -> Par d s (ISet s a)
- intersection :: Ord a => ISet s a -> ISet s a -> Par d s (ISet s a)
- cartesianProd :: (Ord a, Ord b) => ISet s a -> ISet s b -> Par d s (ISet s (a, b))
- cartesianProds :: Ord a => [ISet s a] -> Par d s (ISet s [a])
- traverseSetHP :: Ord b => Maybe HandlerPool -> (a -> Par d s b) -> ISet s a -> Par d s (ISet s b)
- traverseSetHP_ :: Ord b => Maybe HandlerPool -> (a -> Par d s b) -> ISet s a -> ISet s b -> Par d s ()
- cartesianProdHP :: (Ord a, Ord b) => Maybe HandlerPool -> ISet s a -> ISet s b -> Par d s (ISet s (a, b))
- cartesianProdsHP :: Ord a => Maybe HandlerPool -> [ISet s a] -> Par d s (ISet s [a])

# Basic operations

The set 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: this data structure reduces contention between parallel
computations inserting into the map, but all *blocking* computations are not as
scalable. All continuations waiting for not-yet-present elements will currently
share a single queue [2013.09.26].

LVarData1 ISet | An |

OrderedLVarData1 ISet | The |

Foldable (ISet Trvrsbl) | |

Foldable (ISet Frzn) | |

Eq (ISet s v) | Physical identity, just as with |

Show a => Show (ISet Trvrsbl a) | For convenience only; the user could define this. |

Show a => Show (ISet Frzn a) | |

DeepFrz a => DeepFrz (ISet s a) |

newEmptySet :: Ord a => Par d s (ISet s a)Source

Create a new, empty, monotonically growing set.

newSet :: Ord a => Set a -> Par d s (ISet s a)Source

Create a new `ISet`

populated with initial elements.

newFromList :: Ord a => [a] -> Par d s (ISet s a)Source

A simple convenience function. Create a new `ISet`

drawing initial elements from an existing list.

insert :: Ord a => a -> ISet s a -> Par d s ()Source

Put a single element in the set. (WHNF) Strict in the element being put in the set.

waitElem :: Ord a => a -> ISet s a -> Par d s ()Source

Wait for the set to contain a specified element.

# Iteration and callbacks

forEach :: ISet s a -> (a -> Par d s ()) -> Par d s ()Source

Add an (asynchronous) callback that listens for all new elements added to the set.

:: Maybe HandlerPool | optional pool to enroll in |

-> ISet s a | Set to listen to |

-> (a -> Par d s ()) | callback |

-> Par d s () |

Add an (asynchronous) callback that listens for all new elements added to the set, optionally enrolled in a handler pool.

# Quasi-deterministic operations

freezeSetAfter :: ISet s a -> (a -> QPar s ()) -> QPar s ()Source

Freeze an `ISet`

after a specified callback/handler is done running. This
differs from `withCallbacksThenFreeze`

by not taking an additional action to run in
the context of the handlers.

(

)
`freezeSetAfter`

`s`

`f`

== `withCallbacksThenFreeze`

`s`

`f`

'return ()'

withCallbacksThenFreeze :: Eq b => ISet s a -> (a -> QPar s ()) -> QPar s b -> QPar s bSource

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.

# Higher-level derived operations

copy :: Ord a => ISet s a -> Par d s (ISet s a)Source

Return a fresh set which will contain strictly more elements than the input set. That is, things put in the former go in the latter, but not vice versa.

traverseSet :: Ord b => (a -> Par d s b) -> ISet s a -> Par d s (ISet s b)Source

Establish a monotonic map between the input and output sets.

traverseSet_ :: Ord b => (a -> Par d s b) -> ISet s a -> ISet s b -> Par d s ()Source

An imperative-style, in-place version of `traverseSet`

that takes the output set
as an argument.

union :: Ord a => ISet s a -> ISet s a -> Par d s (ISet s a)Source

Return a new set which will (ultimately) contain everything in either input set.

intersection :: Ord a => ISet s a -> ISet s a -> Par d s (ISet s a)Source

Build a new set which will contain the intersection of the two input sets.

cartesianProd :: (Ord a, Ord b) => ISet s a -> ISet s b -> Par d s (ISet s (a, b))Source

Take the cartesian product of two sets.

cartesianProds :: Ord a => [ISet s a] -> Par d s (ISet s [a])Source

Take the cartesian product of several sets.

# Alternate versions of derived ops that expose `HandlerPool`

s they create

traverseSetHP :: Ord b => Maybe HandlerPool -> (a -> Par d s b) -> ISet s a -> Par d s (ISet s b)Source

Variant of `traverseSet`

that optionally ties the handlers to a pool.

traverseSetHP_ :: Ord b => Maybe HandlerPool -> (a -> Par d s b) -> ISet s a -> ISet s b -> Par d s ()Source

Variant of `traverseSet_`

that optionally ties the handlers to a pool.

cartesianProdHP :: (Ord a, Ord b) => Maybe HandlerPool -> ISet s a -> ISet s b -> Par d s (ISet s (a, b))Source

Variant of `cartesianProd`

that optionally ties the handlers to a pool.

cartesianProdsHP :: Ord a => Maybe HandlerPool -> [ISet s a] -> Par d s (ISet s [a])Source

Variant of `cartesianProds`

that optionally ties the handlers to a pool.