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