Skip to content
Snippets Groups Projects
Commit bad78c75 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel :turtle:
Browse files

Add unsafeStatesOfBlock to RefinablePartition

This can be used in cases where the caller can guarantee that the
returned vector isn't referenced any more after the next mutation of
RefinablePartition.
parent b9fd6988
Branches
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ module Data.RefinablePartition
, groupBy
-- * Conversion
, freeze
, unsafeStatesOfBlock
) where
import Control.Monad (forM_, when, foldM)
......@@ -247,6 +248,18 @@ statesOfBlock partition b = do
let slice = VU.slice (block^.startOffset) len (partition^.statesByBlock)
V.convert <$> VUU.freeze slice
-- | Return a vector of all states in a given block.
--
-- Runtime: O(n) for n == number of states in this block
unsafeStatesOfBlock :: RefinablePartition s -> Block -> ST s (VU.Vector State)
unsafeStatesOfBlock partition b = do
block <- getBlock partition b
len <- blockSize partition b
let slice = VU.slice (block^.startOffset) len (partition^.statesByBlock)
VU.unsafeFreeze slice
-- | Split a block into two new blocks for its marked and unmarked states.
--
-- Returns a tuple of (marked block, unmarked block). If there are no marked or
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment