diff --git a/src/MA/Algorithm/Split.hs b/src/MA/Algorithm/Split.hs index 9ee1b5ecab072fe02dc812f1dbce78e71c08c8d9..5b3a3039abd4afc6dfff67ba1a23d0e556353428 100644 --- a/src/MA/Algorithm/Split.hs +++ b/src/MA/Algorithm/Split.hs @@ -71,9 +71,14 @@ splitBlock b = ask >>= \(as, queue) -> lift $ do -- b has marked states, so b1 is guaranteed to be non-empty (Just b1, bunmarked) <- Partition.splitMarked (partition as) b - pmc <- Partition.statesOfBlock (partition as) b1 - >>= mapM (VM.read (h3Cache as)) - >>= return . possibleMajorityCandidate + -- NOTE: We need to use unsafePerformIO here, because all vector sortBy + -- functions expect a pure predicate. Since our predicate is only monadic + -- because we need to _read_ from a mutable vector and doesn't have side + -- effects, this should be safe. + let unsafeH3 = unsafeDupablePerformIO . unsafeSTToIO . VM.read (h3Cache as) + + !pmc <- (possibleMajorityCandidate . V.map unsafeH3) <$> + Partition.statesOfBlock (partition as) b1 -- the pmc occurs in b1, so b1' has to be non-empty (Just b1', b2) <- Partition.splitByM (partition as) b1 @@ -81,12 +86,7 @@ splitBlock b = ask >>= \(as, queue) -> lift $ do blocks <- ((b1':maybeToList bunmarked) ++) <$> case b2 of Nothing -> return [] - -- NOTE: We need to use unsafePerformIO here, because all vector sortBy - -- functions expect a pure predicate. Since our predicate is only monadic - -- because we need to _read_ from a mutable vector and doesn't have side - -- effects, this should be safe. - Just b2' -> Partition.groupBy (partition as) b2' - (unsafeDupablePerformIO . unsafeSTToIO . VM.read (h3Cache as)) + Just b2' -> Partition.groupBy (partition as) b2' unsafeH3 let enqueue = Queue.enqueue queue