lvish-2.0: Parallel scheduler, LVar data structures, and infrastructure to build more.

Safe HaskellTrustworthy

Data.LVar.IStructure

Contents

Description

An I-Structure, also known as an array of IVars, implemented using a boxed vector.

Synopsis

Documentation

data IStructure s a

An I-Structure, also known as an array of IVars.

Instances

LVarData1 IStructure

An IStructure can be treated as a generic container LVar. However, the polymorphic operations are less useful than the monomorphic ones exposed by this module (e.g., forEachHP vs. addHandler).

OrderedLVarData1 IStructure

The IStructures in this module also have the special property that they support a freeze operation which immediately yields a Foldable container without any sorting (see snapFreeze).

Foldable (IStructure Trvrsbl) 
Foldable (IStructure Frzn) 
Eq (IStructure s v) 
Show a => Show (IStructure Trvrsbl a)

For convenience only; the user could define this.

Show a => Show (IStructure Frzn a) 
DeepFrz a => DeepFrz (IStructure s a) 

Basic operations

newIStructure :: Int -> Par e s (IStructure s elt)

Create a new, empty, monotonically growing IStructure of a given size. All entries start off as zero, which must be "bottom".

newIStructureWithCallback :: Int -> (Int -> elt -> Par e s ()) -> Par e s (IStructure s elt)

Register handlers on each internal IVar as it is created. This operation should be more efficient than newIStructure followed by forEachHP.

put :: (NFData elt, Eq elt, HasPut e) => IStructure s elt -> Int -> elt -> Par e s ()

Put a single element in the IStructure at a given index. This variant is deeply strict (NFData).

put_ :: (Eq elt, HasPut e) => IStructure s elt -> Int -> elt -> Par e s ()

Put a single element in the IStructure at a given index. That index must be previously empty. (WHNF) Strict in the element being put in the set.

get :: (Eq elt, HasGet e) => IStructure s elt -> Int -> Par e s elt

Wait for the indexed entry to contain a value, and return that value.

getLength :: IStructure s a -> Par e s Int

Retrieve the number of slots in the IStructure.

Iteration and callbacks

forEachHP

Arguments

:: Maybe HandlerPool

pool to enroll in, if any

-> IStructure s a

IStructure to listen to

-> (Int -> a -> Par e s ())

callback

-> Par e s () 

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

Freezing

freezeIStructure :: HasFreeze e => IStructure s a -> Par e s (Vector (Maybe a))

O(N) complexity, unfortunately. This implementation of IStructures requires freezing each of the individual IVars stored in the array.