lsm-tree-0.1.0.0: Log-structured merge-trees
Safe HaskellSafe-Inferred
LanguageGHC2021

MCG

Synopsis

Documentation

data MCG Source #

Instances

Instances details
Show MCG Source # 
Instance details

Defined in MCG

Methods

showsPrec :: Int -> MCG -> ShowS #

show :: MCG -> String #

showList :: [MCG] -> ShowS #

make Source #

Arguments

:: Word64

a lower bound for the period

-> Word64

initial seed.

-> MCG 

Create a MCG

>>> make 20 04
MCG {m = 23, a = 11, x = 5}
>>> make 101_000_000 20240429
MCG {m = 101000023, a = 197265, x = 20240430}

period :: MCG -> Word64 Source #

Period of the MCG.

Period is usually a bit larger than asked for, we look for the next prime:

>>> let g = make 9 04
>>> period g
10
>>> take 22 (unfoldr (Just . next) g)
[4,7,3,1,0,5,2,6,8,9,4,7,3,1,0,5,2,6,8,9,4,7]

next :: MCG -> (Word64, MCG) Source #

Generate next number.

reject :: Word64 -> MCG -> (Word64, MCG) Source #

Generate next numbers until one less than given bound is generated.

Replacing next with reject n effectively cuts the period to n:

>>> let g = make 9 04
>>> period g
10
>>> take 22 (unfoldr (Just . reject 9) g)
[4,7,3,1,0,5,2,6,8,4,7,3,1,0,5,2,6,8,4,7,3,1]

if n is close enough to actual period of MCG, the rejection ratio is very small.