ganeti
Safe Haskell Safe

Ganeti.SlotMap

Description

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

Synopsis

# Documentation

data Slot Source #

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

Constructors

 Slot FieldsslotOccupied :: Int slotLimit :: Int

#### Instances

Instances details
 Eq Slot # Instance detailsDefined in Ganeti.SlotMap Methods(==) :: Slot -> Slot -> Bool(/=) :: Slot -> Slot -> Bool Ord Slot # Instance detailsDefined in Ganeti.SlotMap Methodscompare :: Slot -> Slot -> Ordering(<) :: Slot -> Slot -> Bool(<=) :: Slot -> Slot -> Bool(>) :: Slot -> Slot -> Bool(>=) :: Slot -> Slot -> Boolmax :: Slot -> Slot -> Slotmin :: Slot -> Slot -> Slot Show Slot # Instance detailsDefined in Ganeti.SlotMap MethodsshowsPrec :: Int -> Slot -> ShowSshow :: Slot -> StringshowList :: [Slot] -> ShowS Arbitrary Slot Instance detailsDefined in Test.Ganeti.SlotMap Methodsarbitrary :: Gen Slotshrink :: Slot -> [Slot]

type SlotMap a = Map a Slot Source #

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 Int Source #

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

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

isOverfull :: SlotMap a -> Bool Source #

Whether any more slots are occupied than available.

occupySlots :: Ord a => SlotMap a -> CountMap a -> SlotMap a Source #

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 -> Bool Source #

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.