Skip to content

Commit

Permalink
refactor(runtime): Move TimeInterval to its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-daniel-gustafsson committed Dec 16, 2021
1 parent 48a1532 commit 75ee08f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
25 changes: 1 addition & 24 deletions src/runtime-prototype/src/Scheduler/Fault.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import qualified Scheduler.Agenda as Agenda
import Scheduler.Agenda (Agenda)
import Scheduler.Event
import qualified Scheduler.Faults as Faults
import Scheduler.TimeInterval
import StuntDouble.LogicalTime
import StuntDouble.Time

Expand Down Expand Up @@ -153,27 +154,3 @@ manipulateEvent e (FaultState fsAll) = case Map.lookup (to e) fsAll of
| contain t ti = applySkew t ti action
| otherwise = t

------------------------------------------------------------------------
-- does Time support inf?
data TimeInterval = TimeInterval {tiFrom :: Time, tiTo :: Time}
deriving stock (Eq, Ord, Show)

contain :: Time -> TimeInterval -> Bool
contain t (TimeInterval a b) = afterTime t a && afterTime b t

-- I'm sure there is some clever data structure for this
newtype TimeIntervals = TimeIntervals (Set TimeInterval)
deriving newtype (Semigroup, Monoid, Show)

emptyIntervals :: TimeIntervals
emptyIntervals = TimeIntervals Set.empty

singleton :: TimeInterval -> TimeIntervals
singleton = TimeIntervals . Set.singleton

contains :: Time -> TimeIntervals -> Bool
contains t (TimeIntervals s) =
not
. Set.null
. Set.filter (contain t)
$ s
32 changes: 32 additions & 0 deletions src/runtime-prototype/src/Scheduler/TimeInterval.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Scheduler.TimeInterval where

import Data.Set (Set)
import qualified Data.Set as Set

import StuntDouble.Time
------------------------------------------------------------------------
-- does Time support inf?
data TimeInterval = TimeInterval {tiFrom :: Time, tiTo :: Time}
deriving stock (Eq, Ord, Show)

contain :: Time -> TimeInterval -> Bool
contain t (TimeInterval a b) = afterTime t a && afterTime b t

-- I'm sure there is some clever data structure for this
newtype TimeIntervals = TimeIntervals (Set TimeInterval)
deriving newtype (Semigroup, Monoid, Show)

emptyIntervals :: TimeIntervals
emptyIntervals = TimeIntervals Set.empty

singleton :: TimeInterval -> TimeIntervals
singleton = TimeIntervals . Set.singleton

contains :: Time -> TimeIntervals -> Bool
contains t (TimeIntervals s) =
not
. Set.null
. Set.filter (contain t)
$ s
1 change: 1 addition & 0 deletions src/runtime-prototype/stunt-double.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ library
Scheduler.Faults
Scheduler.Main
Scheduler.State
Scheduler.TimeInterval
StuntDouble
StuntDouble.ActorMap
StuntDouble.AdminTransport
Expand Down

0 comments on commit 75ee08f

Please sign in to comment.