summaryrefslogtreecommitdiff
path: root/Utility/Bloom.hs
blob: b0988a8c42ff9ec2d51cc7cc7a7b9520a431e730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{- bloomfilter compatability wrapper
 -
 - Copyright 2014 Joey Hess <joey@kitenet.net>
 -
 - License: BSD-2-clause
 -}

{-# LANGUAGE CPP #-}

module Utility.Bloom (
	Bloom,
	safeSuggestSizing,
	Hashable,
	cheapHashes,
	notElemB,

	newMB,
	insertMB,
	unsafeFreezeMB,
) where

#if MIN_VERSION_bloomfilter(2,0,0)
import qualified Data.BloomFilter.Mutable as MBloom
import qualified Data.BloomFilter as Bloom
#else
import qualified Data.BloomFilter as Bloom
#endif
import Data.BloomFilter.Easy (safeSuggestSizing, Bloom)
import Data.BloomFilter.Hash (Hashable, cheapHashes)
import Control.Monad.ST.Safe (ST)

#if MIN_VERSION_bloomfilter(2,0,0)

notElemB :: a -> Bloom a -> Bool
notElemB = Bloom.notElem

newMB :: (a -> [Bloom.Hash]) -> Int -> ST s (MBloom.MBloom s a)
newMB = MBloom.new

insertMB :: MBloom.MBloom s a -> a -> ST s ()
insertMB = MBloom.insert

unsafeFreezeMB :: MBloom.MBloom s a -> ST s (Bloom a)
unsafeFreezeMB = Bloom.unsafeFreeze

#else

notElemB :: a -> Bloom a -> Bool
notElemB = Bloom.notElemB

newMB :: (a -> [Bloom.Hash]) -> Int -> ST s (Bloom.MBloom s a)
newMB = Bloom.newMB

insertMB :: Bloom.MBloom s a -> a -> ST s ()
insertMB = Bloom.insertMB

unsafeFreezeMB :: Bloom.MBloom s a -> ST s (Bloom a)
unsafeFreezeMB = Bloom.unsafeFreezeMB

#endif