Commit 4068d42c authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Don't needlessly update blocks with one state

We can't split them anyways, might as well skip the work done by
updateBlock and splitBlock.

This can make the algorithm roughly twice as fast on some inputs.
parent 7feeed6e
......@@ -161,14 +161,15 @@ collectTouchedBlocks blockS = do
let Edge x _ _ = graph (encoding as) e
b <- Partition.blockOfState (partition as) x
unlessM (Partition.hasMarked (partition as) b) $ do
wCx <- readSTRef =<< VM.read (lastW as) (fromEdgeRef e)
let v0 = snd3 $ RI.update @h [] wCx
modifySTRef markedBlocks ((b, v0):)
unlessM ((==1) <$> Partition.blockSize (partition as) b) $ do
unlessM (Partition.hasMarked (partition as) b) $ do
wCx <- readSTRef =<< VM.read (lastW as) (fromEdgeRef e)
let v0 = snd3 $ RI.update @h [] wCx
modifySTRef markedBlocks ((b, v0):)
whenM (null <$> VM.read (toSub as) x) $
Partition.mark (partition as) x
whenM (null <$> VM.read (toSub as) x) $
Partition.mark (partition as) x
VM.modify (toSub as) (e:) x
VM.modify (toSub as) (e:) x
lift $ readSTRef markedBlocks
......@@ -46,7 +46,7 @@ collectTouchedBlocksSpec = describe "collectTouchedBlocks" $ do
`shouldBe` []
it "returns the correct block when predecessors exist" $ do
withState @Powerset (enc [True, False] [(0, (), 1)])
withState @Powerset (enc [True, True, False] [(0, (), 2), (1, (), 2)])
(map fst <$> collectTouchedBlocks (Block 1))
`shouldBe` [Block 0]
......@@ -159,13 +159,6 @@ updateBlockSpec = describe "updateBlock" $ do
splitBlockSpec :: Spec
splitBlockSpec = describe "splitBlock" $ do
it "handles the simple case of a one-element block"
$ let res = withState @Powerset (enc [True, False] [(0, (), 1)]) $ do
[(b, v0)] <- collectTouchedBlocks (Block 1)
updateBlock b v0
splitBlock b
in res `shouldBe` [0]
it "splits blocks into marked and unmaked"
$ let
res =
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment