module Simulation.Aivika.Lattice.QueueStrategy () where
import Control.Monad.Trans
import Simulation.Aivika.Trans
import qualified Simulation.Aivika.Trans.DoubleLinkedList as LL
import Simulation.Aivika.Lattice.Internal.LIO
import Simulation.Aivika.Lattice.Ref.Base
instance QueueStrategy LIO FCFS where
newtype StrategyQueue LIO FCFS a = FCFSQueueLIO (LL.DoubleLinkedList LIO a)
newStrategyQueue s = fmap FCFSQueueLIO LL.newList
strategyQueueNull (FCFSQueueLIO q) = LL.listNull q
instance DequeueStrategy LIO FCFS where
strategyDequeue (FCFSQueueLIO q) =
do i <- LL.listFirst q
LL.listRemoveFirst q
return i
instance EnqueueStrategy LIO FCFS where
strategyEnqueue (FCFSQueueLIO q) i = LL.listAddLast q i
instance QueueStrategy LIO LCFS where
newtype StrategyQueue LIO LCFS a = LCFSQueueLIO (LL.DoubleLinkedList LIO a)
newStrategyQueue s = fmap LCFSQueueLIO LL.newList
strategyQueueNull (LCFSQueueLIO q) = LL.listNull q
instance DequeueStrategy LIO LCFS where
strategyDequeue (LCFSQueueLIO q) =
do i <- LL.listFirst q
LL.listRemoveFirst q
return i
instance EnqueueStrategy LIO LCFS where
strategyEnqueue (LCFSQueueLIO q) i = LL.listInsertFirst q i