Safe Haskell | Safe |
---|---|
Language | Haskell98 |
This module defines the FastWeakBag
type, which represents a mutable
collection of items that does not cause the items to be retained in memory.
This is useful for situations where a value needs to be inspected or modified
if it is still alive, but can be ignored if it is dead.
Synopsis
- data FastWeakBag a
- data FastWeakBagTicket a
- empty :: IO (FastWeakBag a)
- isEmpty :: FastWeakBag a -> IO Bool
- insert :: a -> FastWeakBag a -> IO (FastWeakBagTicket a)
- traverse :: forall a m. MonadIO m => FastWeakBag a -> (a -> m ()) -> m ()
- remove :: FastWeakBagTicket a -> IO ()
- _weakBag_children :: FastWeakBag a -> IORef (IntMap (Weak a))
Documentation
data FastWeakBag a Source #
A FastWeakBag
holds a set of values of type a
, but does not retain them -
that is, they can still be garbage-collected. As long as the a
values remain
alive, the FastWeakBag
will continue to refer to them.
data FastWeakBagTicket a Source #
When inserting an item into a FastWeakBag
, a FastWeakBagTicket
is returned. If
the caller retains the ticket, the item is guranteed to stay in memory (and
thus in the FastWeakBag
). The ticket can also be used to remove the item from
the FastWeakBag
prematurely (i.e. while it is still alive), using remove
.
empty :: IO (FastWeakBag a) Source #
Create an empty FastWeakBag
.
isEmpty :: FastWeakBag a -> IO Bool Source #
Check whether a FastWeakBag
is empty.
:: a | The item |
-> FastWeakBag a | The |
-> IO (FastWeakBagTicket a) | Returns a |
Insert an item into a FastWeakBag
.
traverse :: forall a m. MonadIO m => FastWeakBag a -> (a -> m ()) -> m () Source #
Visit every node in the given list. If new nodes are appended during the traversal, they will not be visited. Every live node that was in the list when the traversal began will be visited exactly once; however, no guarantee is made about the order of the traversal.
remove :: FastWeakBagTicket a -> IO () Source #
Remove an item from the FastWeakBag
; does nothing if invoked multiple times
on the same FastWeakBagTicket
.
Internal functions
_weakBag_children :: FastWeakBag a -> IORef (IntMap (Weak a)) Source #
Map of items contained by the FastWeakBag