Safe Haskell | Safe-Infered |
---|
A data structure for measuring how many of a number of available slots are taken.
- data Slot = Slot {
- slotOccupied :: Int
- slotLimit :: Int
- type SlotMap a = Map a Slot
- type CountMap a = Map a Int
- toCountMap :: SlotMap a -> CountMap a
- isOverfull :: SlotMap a -> Bool
- occupySlots :: Ord a => SlotMap a -> CountMap a -> SlotMap a
- hasSlotsFor :: Ord a => SlotMap a -> CountMap a -> Bool
Documentation
A resource with [limit] available units and [occupied] of them taken.
Slot | |
|
type SlotMap a = Map a SlotSource
A set of keys of type a
and how many slots are available and (to be)
occupied per key.
Some keys can be overfull (more slots occupied than available).
toCountMap :: SlotMap a -> CountMap aSource
isOverfull :: SlotMap a -> BoolSource
Whether any more slots are occupied than available.
occupySlots :: Ord a => SlotMap a -> CountMap a -> SlotMap aSource
hasSlotsFor :: Ord a => SlotMap a -> CountMap a -> BoolSource
Whether the SlotMap
has enough slots free to accomodate the given
counts.
The SlotMap
is allowed to be overfull in some keys; this function
still returns True as long as as adding the counts to the SlotMap
would
not *create or increase* overfull keys.
Adding counts > 0 for a key which is not in the SlotMap
does create
overfull keys.