{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, FunctionalDependencies, UndecidableInstances #-}
module Simulation.Aivika.Trans.QueueStrategy where
import Control.Monad
import Data.Maybe
import Simulation.Aivika.Trans.Internal.Types
class Monad m => QueueStrategy m s where
data StrategyQueue m s :: * -> *
newStrategyQueue :: s
-> Simulation m (StrategyQueue m s a)
strategyQueueNull :: StrategyQueue m s a
-> Event m Bool
class QueueStrategy m s => DequeueStrategy m s where
strategyDequeue :: StrategyQueue m s a
-> Event m a
class DequeueStrategy m s => EnqueueStrategy m s where
strategyEnqueue :: StrategyQueue m s a
-> a
-> Event m ()
class DequeueStrategy m s => PriorityQueueStrategy m s p | s -> p where
strategyEnqueueWithPriority :: StrategyQueue m s a
-> p
-> a
-> Event m ()
class DequeueStrategy m s => DeletingQueueStrategy m s where
strategyQueueDelete :: Eq a
=> StrategyQueue m s a
-> a
-> Event m Bool
strategyQueueDelete StrategyQueue m s a
s a
a =
(Point m -> m Bool) -> Event m Bool
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Bool) -> Event m Bool)
-> (Point m -> m Bool) -> Event m Bool
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Maybe a
x <- Point m -> Event m (Maybe a) -> m (Maybe a)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (Maybe a) -> m (Maybe a))
-> Event m (Maybe a) -> m (Maybe a)
forall a b. (a -> b) -> a -> b
$ StrategyQueue m s a -> (a -> Bool) -> Event m (Maybe a)
forall a. StrategyQueue m s a -> (a -> Bool) -> Event m (Maybe a)
forall (m :: * -> *) s a.
DeletingQueueStrategy m s =>
StrategyQueue m s a -> (a -> Bool) -> Event m (Maybe a)
strategyQueueDeleteBy StrategyQueue m s a
s (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a)
Bool -> m Bool
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> Bool
forall a. Maybe a -> Bool
isJust Maybe a
x)
strategyQueueDeleteBy :: StrategyQueue m s a
-> (a -> Bool)
-> Event m (Maybe a)
strategyQueueContains :: Eq a
=> StrategyQueue m s a
-> a
-> Event m Bool
strategyQueueContains StrategyQueue m s a
s a
a =
(Point m -> m Bool) -> Event m Bool
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Bool) -> Event m Bool)
-> (Point m -> m Bool) -> Event m Bool
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Maybe a
x <- Point m -> Event m (Maybe a) -> m (Maybe a)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (Maybe a) -> m (Maybe a))
-> Event m (Maybe a) -> m (Maybe a)
forall a b. (a -> b) -> a -> b
$ StrategyQueue m s a -> (a -> Bool) -> Event m (Maybe a)
forall a. StrategyQueue m s a -> (a -> Bool) -> Event m (Maybe a)
forall (m :: * -> *) s a.
DeletingQueueStrategy m s =>
StrategyQueue m s a -> (a -> Bool) -> Event m (Maybe a)
strategyQueueContainsBy StrategyQueue m s a
s (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a)
Bool -> m Bool
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> Bool
forall a. Maybe a -> Bool
isJust Maybe a
x)
strategyQueueContainsBy :: StrategyQueue m s a
-> (a -> Bool)
-> Event m (Maybe a)
data FCFS = FCFS deriving (FCFS -> FCFS -> Bool
(FCFS -> FCFS -> Bool) -> (FCFS -> FCFS -> Bool) -> Eq FCFS
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FCFS -> FCFS -> Bool
== :: FCFS -> FCFS -> Bool
$c/= :: FCFS -> FCFS -> Bool
/= :: FCFS -> FCFS -> Bool
Eq, Eq FCFS
Eq FCFS =>
(FCFS -> FCFS -> Ordering)
-> (FCFS -> FCFS -> Bool)
-> (FCFS -> FCFS -> Bool)
-> (FCFS -> FCFS -> Bool)
-> (FCFS -> FCFS -> Bool)
-> (FCFS -> FCFS -> FCFS)
-> (FCFS -> FCFS -> FCFS)
-> Ord FCFS
FCFS -> FCFS -> Bool
FCFS -> FCFS -> Ordering
FCFS -> FCFS -> FCFS
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FCFS -> FCFS -> Ordering
compare :: FCFS -> FCFS -> Ordering
$c< :: FCFS -> FCFS -> Bool
< :: FCFS -> FCFS -> Bool
$c<= :: FCFS -> FCFS -> Bool
<= :: FCFS -> FCFS -> Bool
$c> :: FCFS -> FCFS -> Bool
> :: FCFS -> FCFS -> Bool
$c>= :: FCFS -> FCFS -> Bool
>= :: FCFS -> FCFS -> Bool
$cmax :: FCFS -> FCFS -> FCFS
max :: FCFS -> FCFS -> FCFS
$cmin :: FCFS -> FCFS -> FCFS
min :: FCFS -> FCFS -> FCFS
Ord, Int -> FCFS -> ShowS
[FCFS] -> ShowS
FCFS -> String
(Int -> FCFS -> ShowS)
-> (FCFS -> String) -> ([FCFS] -> ShowS) -> Show FCFS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FCFS -> ShowS
showsPrec :: Int -> FCFS -> ShowS
$cshow :: FCFS -> String
show :: FCFS -> String
$cshowList :: [FCFS] -> ShowS
showList :: [FCFS] -> ShowS
Show)
data LCFS = LCFS deriving (LCFS -> LCFS -> Bool
(LCFS -> LCFS -> Bool) -> (LCFS -> LCFS -> Bool) -> Eq LCFS
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LCFS -> LCFS -> Bool
== :: LCFS -> LCFS -> Bool
$c/= :: LCFS -> LCFS -> Bool
/= :: LCFS -> LCFS -> Bool
Eq, Eq LCFS
Eq LCFS =>
(LCFS -> LCFS -> Ordering)
-> (LCFS -> LCFS -> Bool)
-> (LCFS -> LCFS -> Bool)
-> (LCFS -> LCFS -> Bool)
-> (LCFS -> LCFS -> Bool)
-> (LCFS -> LCFS -> LCFS)
-> (LCFS -> LCFS -> LCFS)
-> Ord LCFS
LCFS -> LCFS -> Bool
LCFS -> LCFS -> Ordering
LCFS -> LCFS -> LCFS
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: LCFS -> LCFS -> Ordering
compare :: LCFS -> LCFS -> Ordering
$c< :: LCFS -> LCFS -> Bool
< :: LCFS -> LCFS -> Bool
$c<= :: LCFS -> LCFS -> Bool
<= :: LCFS -> LCFS -> Bool
$c> :: LCFS -> LCFS -> Bool
> :: LCFS -> LCFS -> Bool
$c>= :: LCFS -> LCFS -> Bool
>= :: LCFS -> LCFS -> Bool
$cmax :: LCFS -> LCFS -> LCFS
max :: LCFS -> LCFS -> LCFS
$cmin :: LCFS -> LCFS -> LCFS
min :: LCFS -> LCFS -> LCFS
Ord, Int -> LCFS -> ShowS
[LCFS] -> ShowS
LCFS -> String
(Int -> LCFS -> ShowS)
-> (LCFS -> String) -> ([LCFS] -> ShowS) -> Show LCFS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LCFS -> ShowS
showsPrec :: Int -> LCFS -> ShowS
$cshow :: LCFS -> String
show :: LCFS -> String
$cshowList :: [LCFS] -> ShowS
showList :: [LCFS] -> ShowS
Show)
data SIRO = SIRO deriving (SIRO -> SIRO -> Bool
(SIRO -> SIRO -> Bool) -> (SIRO -> SIRO -> Bool) -> Eq SIRO
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SIRO -> SIRO -> Bool
== :: SIRO -> SIRO -> Bool
$c/= :: SIRO -> SIRO -> Bool
/= :: SIRO -> SIRO -> Bool
Eq, Eq SIRO
Eq SIRO =>
(SIRO -> SIRO -> Ordering)
-> (SIRO -> SIRO -> Bool)
-> (SIRO -> SIRO -> Bool)
-> (SIRO -> SIRO -> Bool)
-> (SIRO -> SIRO -> Bool)
-> (SIRO -> SIRO -> SIRO)
-> (SIRO -> SIRO -> SIRO)
-> Ord SIRO
SIRO -> SIRO -> Bool
SIRO -> SIRO -> Ordering
SIRO -> SIRO -> SIRO
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SIRO -> SIRO -> Ordering
compare :: SIRO -> SIRO -> Ordering
$c< :: SIRO -> SIRO -> Bool
< :: SIRO -> SIRO -> Bool
$c<= :: SIRO -> SIRO -> Bool
<= :: SIRO -> SIRO -> Bool
$c> :: SIRO -> SIRO -> Bool
> :: SIRO -> SIRO -> Bool
$c>= :: SIRO -> SIRO -> Bool
>= :: SIRO -> SIRO -> Bool
$cmax :: SIRO -> SIRO -> SIRO
max :: SIRO -> SIRO -> SIRO
$cmin :: SIRO -> SIRO -> SIRO
min :: SIRO -> SIRO -> SIRO
Ord, Int -> SIRO -> ShowS
[SIRO] -> ShowS
SIRO -> String
(Int -> SIRO -> ShowS)
-> (SIRO -> String) -> ([SIRO] -> ShowS) -> Show SIRO
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SIRO -> ShowS
showsPrec :: Int -> SIRO -> ShowS
$cshow :: SIRO -> String
show :: SIRO -> String
$cshowList :: [SIRO] -> ShowS
showList :: [SIRO] -> ShowS
Show)
data StaticPriorities = StaticPriorities deriving (StaticPriorities -> StaticPriorities -> Bool
(StaticPriorities -> StaticPriorities -> Bool)
-> (StaticPriorities -> StaticPriorities -> Bool)
-> Eq StaticPriorities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StaticPriorities -> StaticPriorities -> Bool
== :: StaticPriorities -> StaticPriorities -> Bool
$c/= :: StaticPriorities -> StaticPriorities -> Bool
/= :: StaticPriorities -> StaticPriorities -> Bool
Eq, Eq StaticPriorities
Eq StaticPriorities =>
(StaticPriorities -> StaticPriorities -> Ordering)
-> (StaticPriorities -> StaticPriorities -> Bool)
-> (StaticPriorities -> StaticPriorities -> Bool)
-> (StaticPriorities -> StaticPriorities -> Bool)
-> (StaticPriorities -> StaticPriorities -> Bool)
-> (StaticPriorities -> StaticPriorities -> StaticPriorities)
-> (StaticPriorities -> StaticPriorities -> StaticPriorities)
-> Ord StaticPriorities
StaticPriorities -> StaticPriorities -> Bool
StaticPriorities -> StaticPriorities -> Ordering
StaticPriorities -> StaticPriorities -> StaticPriorities
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: StaticPriorities -> StaticPriorities -> Ordering
compare :: StaticPriorities -> StaticPriorities -> Ordering
$c< :: StaticPriorities -> StaticPriorities -> Bool
< :: StaticPriorities -> StaticPriorities -> Bool
$c<= :: StaticPriorities -> StaticPriorities -> Bool
<= :: StaticPriorities -> StaticPriorities -> Bool
$c> :: StaticPriorities -> StaticPriorities -> Bool
> :: StaticPriorities -> StaticPriorities -> Bool
$c>= :: StaticPriorities -> StaticPriorities -> Bool
>= :: StaticPriorities -> StaticPriorities -> Bool
$cmax :: StaticPriorities -> StaticPriorities -> StaticPriorities
max :: StaticPriorities -> StaticPriorities -> StaticPriorities
$cmin :: StaticPriorities -> StaticPriorities -> StaticPriorities
min :: StaticPriorities -> StaticPriorities -> StaticPriorities
Ord, Int -> StaticPriorities -> ShowS
[StaticPriorities] -> ShowS
StaticPriorities -> String
(Int -> StaticPriorities -> ShowS)
-> (StaticPriorities -> String)
-> ([StaticPriorities] -> ShowS)
-> Show StaticPriorities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StaticPriorities -> ShowS
showsPrec :: Int -> StaticPriorities -> ShowS
$cshow :: StaticPriorities -> String
show :: StaticPriorities -> String
$cshowList :: [StaticPriorities] -> ShowS
showList :: [StaticPriorities] -> ShowS
Show)