lvish-1.1.1.1: 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 Source

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 d s (IStructure s elt)Source

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 d s ()) -> Par d s (IStructure s elt)Source

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) => IStructure s elt -> Int -> elt -> Par d s ()Source

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

put_ :: Eq elt => IStructure s elt -> Int -> elt -> Par d s ()Source

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 => IStructure s elt -> Int -> Par d s eltSource

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

getLength :: IStructure s a -> Par d s IntSource

Retrieve the number of slots in the IStructure.

Iteration and callbacks

forEachHPSource

Arguments

:: Maybe HandlerPool

pool to enroll in, if any

-> IStructure s a

IStructure to listen to

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

callback

-> Par d s () 

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

Freezing

freezeIStructure :: IStructure s a -> Par QuasiDet s (Vector (Maybe a))Source

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