ganeti

Safe HaskellSafe

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 

Fields

Instances
Eq Slot # 
Instance details

Defined in Ganeti.SlotMap

Methods

(==) :: Slot -> Slot -> Bool

(/=) :: Slot -> Slot -> Bool

Ord Slot # 
Instance details

Defined in Ganeti.SlotMap

Methods

compare :: Slot -> Slot -> Ordering

(<) :: Slot -> Slot -> Bool

(<=) :: Slot -> Slot -> Bool

(>) :: Slot -> Slot -> Bool

(>=) :: Slot -> Slot -> Bool

max :: Slot -> Slot -> Slot

min :: Slot -> Slot -> Slot

Show Slot # 
Instance details

Defined in Ganeti.SlotMap

Methods

showsPrec :: Int -> Slot -> ShowS

show :: Slot -> String

showList :: [Slot] -> ShowS

Arbitrary Slot 
Instance details

Defined in Test.Ganeti.SlotMap

Methods

arbitrary :: Gen Slot

shrink :: 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.

toCountMap :: SlotMap a -> CountMap a Source #

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.