22module Main (main ) where
33
44import qualified Data.BloomFilter as B (BitsPerEntry , BloomPolicy , BloomSize ,
5- FPR , Hashable )
5+ FPR , Hashable , Salt )
66import qualified Data.BloomFilter.Blocked as B.Blocked
77import qualified Data.BloomFilter.Classic as B.Classic
88
@@ -142,23 +142,26 @@ actualFalsePositiveRate bloomimpl policy n g0 =
142142countFalsePositives :: forall bloom . BloomImpl bloom
143143 -> B. BloomPolicy -> Int -> StdGen -> Int
144144countFalsePositives BloomImpl {.. } policy n g0 =
145- let (! g0', ! g0'') = splitGen g0
145+ let (! g01, ! g02) = splitGen g0
146+
147+ -- create a random salt
148+ (! salt, ! g03) = uniform g02
146149
147150 -- create a bloom filter from n elements from g0
148151 size = sizeForPolicy policy n
149152
150153 xs_b :: bloom Int
151- ! xs_b = unfold size nextElement (g0' , 0 )
154+ ! xs_b = unfold salt size nextElement (g01 , 0 )
152155
153156 -- and a set, so we can make sure we don't count true positives
154157 xs_s :: IntSet
155- ! xs_s = IntSet. fromList (unfoldr nextElement (g0' , 0 ))
158+ ! xs_s = IntSet. fromList (unfoldr nextElement (g01 , 0 ))
156159
157160 -- now for a different random sequence (that will mostly not overlap)
158161 -- count the number of false positives
159162 in length
160163 [ ()
161- | y <- unfoldr nextElement (g0'' , 0 )
164+ | y <- unfoldr nextElement (g03 , 0 )
162165 , y `elem` xs_b -- Bloom filter reports positive
163166 , not (y `IntSet.member` xs_s) -- but it is not a true positive
164167 ]
@@ -177,7 +180,7 @@ data BloomImpl bloom = BloomImpl {
177180 policyFPR :: B. BloomPolicy -> B. FPR ,
178181 sizeForPolicy :: B. BloomPolicy -> Int -> B. BloomSize ,
179182 unfold :: forall a b . B. Hashable a
180- => B. BloomSize -> (b -> Maybe (a , b )) -> b -> bloom a ,
183+ => B. Salt -> B. BloomSize -> (b -> Maybe (a , b )) -> b -> bloom a ,
181184 elem :: forall a . B. Hashable a => a -> bloom a -> Bool
182185 }
183186
0 commit comments