Skip to content

Commit

Permalink
another IntSet replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Mar 4, 2024
1 parent ad5c589 commit bf9aaa7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/swarm-engine/Swarm/Game/State/Robot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import Data.List.NonEmpty qualified as NE
import Data.Map (Map)
import Data.Map qualified as M
import Data.Maybe (fromMaybe, mapMaybe)
import Data.Set qualified as S
import Data.Tuple (swap)
import GHC.Generics (Generic)
import Swarm.Game.CESK (CESK (Waiting))
Expand Down Expand Up @@ -314,6 +313,7 @@ wakeUpRobotsDoneSleeping time = do
Just wakeableRIDs -> do
robots <- use robotMap
let robotIdSet = IM.keysSet robots

wakeableRIDsSet = IS.fromList wakeableRIDs

-- Limit ourselves to the robots that have not expired in their sleep
Expand Down Expand Up @@ -361,8 +361,8 @@ wakeWatchingRobots myID currentTick loc = do
wakeTimes :: [(RID, TickNumber)]
wakeTimes = mapMaybe (sequenceA . (view robotID &&& waitingUntil)) botsWatchingThisLoc

wakeTimesToPurge :: Map TickNumber (S.Set RID)
wakeTimesToPurge = M.fromListWith (<>) $ map (fmap S.singleton . swap) wakeTimes
wakeTimesToPurge :: Map TickNumber IntSet
wakeTimesToPurge = M.fromListWith (<>) $ map (fmap IS.singleton . swap) wakeTimes

-- Step 3: Take these robots out of their time-indexed slot in "waitingRobots".
-- To preserve performance, this should be done without iterating over the
Expand All @@ -373,7 +373,7 @@ wakeWatchingRobots myID currentTick loc = do
-- But we shall not worry about cleaning those up here;
-- they will be "garbage collected" as a matter of course
-- when their tick comes up in "wakeUpRobotsDoneSleeping".
f (k, botsToRemove) = M.adjust (filter (`S.notMember` botsToRemove)) k
f (k, botsToRemove) = M.adjust (filter (`IS.notMember` botsToRemove)) k

-- Step 4: Re-add the watching bots to be awakened ASAP:
wakeableBotIds = map fst wakeTimes
Expand Down

0 comments on commit bf9aaa7

Please sign in to comment.