Safe Haskell | Trustworthy |
---|

An I-structure (array) of *positive* numbers. A `NatArray`

cannot store zeros.

This particular implementation makes a trade-off between expressiveness (monomorphic in array contents) and efficiency. The efficiency gained of course is that the array may be unboxed, and we don't need extra bits to store empty/full status.

*However*, relative to Data.LVar.IStructure, there is a performance disadvantage as
well. As of [2013.09.28] and their initial release, `NatArray`

s are implemented as a
*single* `LVar`

, which means they share a single wait-list of blocked computations.
If there are many computations blocking on different elements within a `NatArray`

,
scalability will be much worse than with other `IStructure`

implementations.

The holy grail is to get unboxed arrays and scalable blocking, but we don't have this yet.

Finally, note that this data-structure has an EXPERIMENTAL status and may be removed in future releases as we find better ways to support unboxed array structures with per-element synchronization.

- data NatArray s a
- newNatArray :: forall elt e s. (Storable elt, Num elt) => Int -> Par e s (NatArray s elt)
- put :: forall s e elt. (Storable elt, AtomicBits elt, Num elt, Show elt, HasPut e) => NatArray s elt -> Int -> elt -> Par e s ()
- get :: forall s e elt. (Storable elt, AtomicBits elt, Num elt, HasGet e) => NatArray s elt -> Int -> Par e s elt
- forEach :: (Num a, Storable a, Eq a) => NatArray s a -> (Int -> a -> Par e s ()) -> Par e s ()
- forEachHP :: (Storable a, Eq a, Num a) => Maybe HandlerPool -> NatArray s a -> (Int -> a -> Par e s ()) -> Par e s ()

# Basic operations

data NatArray s a

An array of bit-fields with a monotonic OR operation. This can be used to model a set of Ints by setting the vector entries to zero or one, but it can also model other finite lattices for each index. newtype NatArray s a = NatArray (LVar s (M.IOVector a) (Int,a))

newNatArray :: forall elt e s. (Storable elt, Num elt) => Int -> Par e s (NatArray s elt)

Physical identity, just as with IORefs. instance Eq (NatArray s v) where NatArray lv1 == NatArray lv2 = state lv1 == state lv2

Create a new, empty, monotonically growing `NatArray`

of a given size.
All entries start off as zero, which must be BOTTOM.

put :: forall s e elt. (Storable elt, AtomicBits elt, Num elt, Show elt, HasPut e) => NatArray s elt -> Int -> elt -> Par e s ()

Put a single element in the array. That slot must be previously empty. (WHNF) Strict in the element being put in the set.

get :: forall s e elt. (Storable elt, AtomicBits elt, Num elt, HasGet e) => NatArray s elt -> Int -> Par e s elt

Wait for an indexed entry to contain a non-zero value.

Warning: this is inefficient if it needs to block, because the deltaThresh must monitor EVERY new addition.