module RandomCycle.List
(
uniformPartition,
uniformPartitionThin,
partitionLengths,
partitionFromBits,
uniformCycle,
uniformCyclePartition,
uniformCyclePartitionThin,
)
where
import Control.Monad.Primitive (PrimMonad)
import qualified Data.Vector as V
import RandomCycle.List.Partition
import qualified RandomCycle.Vector as RV
import System.Random.Stateful (StatefulGen)
uniformCycle :: (PrimMonad m, StatefulGen g m) => Int -> g -> m [(Int, Int)]
uniformCycle :: Int -> g -> m [(Int, Int)]
uniformCycle Int
n g
g = Vector (Int, Int) -> [(Int, Int)]
forall a. Vector a -> [a]
V.toList (Vector (Int, Int) -> [(Int, Int)])
-> m (Vector (Int, Int)) -> m [(Int, Int)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> g -> m (Vector (Int, Int))
forall g (m :: * -> *).
(StatefulGen g m, PrimMonad m) =>
Int -> g -> m (Vector (Int, Int))
RV.uniformCycle Int
n g
g
uniformCyclePartition :: (PrimMonad m, StatefulGen g m) => Int -> g -> m [(Int, Int)]
uniformCyclePartition :: Int -> g -> m [(Int, Int)]
uniformCyclePartition Int
n g
g = Vector (Int, Int) -> [(Int, Int)]
forall a. Vector a -> [a]
V.toList (Vector (Int, Int) -> [(Int, Int)])
-> m (Vector (Int, Int)) -> m [(Int, Int)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> g -> m (Vector (Int, Int))
forall g (m :: * -> *).
(StatefulGen g m, PrimMonad m) =>
Int -> g -> m (Vector (Int, Int))
RV.uniformCyclePartition Int
n g
g
uniformCyclePartitionThin ::
(PrimMonad m, StatefulGen g m) =>
Int ->
((Int, Int) -> Bool) ->
Int ->
g ->
m (Maybe [(Int, Int)])
uniformCyclePartitionThin :: Int -> ((Int, Int) -> Bool) -> Int -> g -> m (Maybe [(Int, Int)])
uniformCyclePartitionThin Int
maxit (Int, Int) -> Bool
r Int
n g
g =
(Vector (Int, Int) -> [(Int, Int)])
-> Maybe (Vector (Int, Int)) -> Maybe [(Int, Int)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector (Int, Int) -> [(Int, Int)]
forall a. Vector a -> [a]
V.toList
(Maybe (Vector (Int, Int)) -> Maybe [(Int, Int)])
-> m (Maybe (Vector (Int, Int))) -> m (Maybe [(Int, Int)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> ((Int, Int) -> Bool)
-> Int
-> g
-> m (Maybe (Vector (Int, Int)))
forall g (m :: * -> *).
(StatefulGen g m, PrimMonad m) =>
Int
-> ((Int, Int) -> Bool)
-> Int
-> g
-> m (Maybe (Vector (Int, Int)))
RV.uniformCyclePartitionThin Int
maxit (Int, Int) -> Bool
r Int
n g
g