module Algo.MaxMinRate where import Types import Heap import Algo.Common createHeap :: [Time] -> Heap Unit createHeap [] = Nil createHeap (t:ts) = insert (Unit (fromIntegral t) t 1 0) $ createHeap ts -- we use 1/speed as metric updateHeap :: HeapUpdateFunc updateHeap start_t fin_t (h, nh) = if (div start_t Types.packet_t /= div fin_t Types.packet_t) then let inc_rem x = x {rem_p = rem_p x + 1} restore x h = insert (x {rem_p = 1}) h in (foldr restore (fmap inc_rem h) nh, emptyHeap) -- "bring back" clients without available packets every 20ms else (h, nh)