Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module implements a reservation multi-map.
Each insert is indexed by a key; many inserts (of the same or different items) may be performed on the same key.
A reservation data structure is one that allows multiple inserts of the same item, by returning a unique handle for each insert operation that must be given to the delete operation.
This API is experimental at the moment, and parts of it may change.
Synopsis
- data RMMap k a = RMMap {}
- _handles :: forall k a. Lens' (RMMap k a) RHandles
- _content :: forall k a k a. Lens (RMMap k a) (RMMap k a) (Map k (Entries a)) (Map k (Entries a))
- data Delete k a
- checkValidity :: RMMap k a -> Maybe Text
- checkHandle :: RMMap k a -> Delete k a -> Bool
- empty :: RMMap k a
- isEmpty :: RMMap k a -> Bool
- (!) :: Ord k => RMMap k a -> k -> Seq a
- toList :: RMMap k a -> [Delete k a]
- enqueue :: Ord k => (k, a) -> RMMap k a -> (Delete k a, RMMap k a)
- unqueue :: Ord k => Delete k a -> RMMap k a -> (Maybe (k, a), RMMap k a)
- dequeue :: Ord k => k -> RMMap k a -> (Maybe (Delete k a, a), RMMap k a)
Documentation
_content :: forall k a k a. Lens (RMMap k a) (RMMap k a) (Map k (Entries a)) (Map k (Entries a)) Source #
Instances
Eq k => Eq (Delete k a) Source # | |
Ord k => Ord (Delete k a) Source # | |
Read k => Read (Delete k a) Source # | |
Show k => Show (Delete k a) Source # | |
Generic (Delete k a) Source # | |
type Rep (Delete k a) Source # | |
Defined in Data.Rsv.RMMap type Rep (Delete k a) = D1 (MetaData "Delete" "Data.Rsv.RMMap" "schedule-0.3.0.0-rXAR2JhUGJ487cqZKqedA" False) (C1 (MetaCons "Delete" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 k) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 RHandle))) |
checkValidity :: RMMap k a -> Maybe Text Source #
Check the map that its internal invariants all hold.
You must run this on every instance obtained not via the API functions here.
For example, you must run this on instances obtained via deserialisation,
which in general cannot check the complex invariants maintained by the API
functions. Also, for all handles you obtain via a similarly non-standard
method, including by deserialisation of a parent data structure, you must
run
.checkHandle
map handle
Nothing
means the check passed;
gives a failure reason.Just
errmsg
Note: this does not guard against all malicious behaviour, but it does guard against violation (either malicious or accidental) of the runtime invariants assumed by this data structure.
checkHandle :: RMMap k a -> Delete k a -> Bool Source #
Check that an existing handle is consistent with the current state of the structure, i.e. it is not a handle that could be generated in the future.
Read operations
Write operations
enqueue :: Ord k => (k, a) -> RMMap k a -> (Delete k a, RMMap k a) Source #
Append an item on a key, returning a handle to remove it with. The same item may be added twice, in which case it will occupy multiple positions in the map, and the handles distinguish these occurences.