Safe HaskellSafe-Infered



A data structure for measuring how many of a number of available slots are taken.



data Slot Source

A resource with [limit] available units and [occupied] of them taken.




slotOccupied :: Int
slotLimit :: Int


Eq Slot 
Ord Slot 
Show Slot 
Arbitrary 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).

type CountMap a = Map a IntSource

A set of keys of type a and how many there are of each.

toCountMap :: SlotMap a -> CountMap aSource

Turns a SlotMap into a CountMap by throwing away the limits.

isOverfull :: SlotMap a -> BoolSource

Whether any more slots are occupied than available.

occupySlots :: Ord a => SlotMap a -> CountMap a -> SlotMap aSource

Fill slots of a SlotMaps by adding the given counts. Keys with counts that don't appear in the SlotMap get a limit of 0.

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.