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

Data.BloomFilter.Classic.Internal

Description

This module defines the Bloom and MBloom types and all the functions that need direct knowledge of and access to the representation. This forms the trusted base.

Synopsis

Mutable Bloom filters

data MBloom s a Source #

A mutable Bloom filter, for use within the ST monad.

Instances

Instances details
Show (MBloom s a) Source # 
Instance details

Defined in Data.BloomFilter.Classic.Internal

Methods

showsPrec :: Int -> MBloom s a -> ShowS #

show :: MBloom s a -> String #

showList :: [MBloom s a] -> ShowS #

NFData (MBloom s a) Source # 
Instance details

Defined in Data.BloomFilter.Classic.Internal

Methods

rnf :: MBloom s a -> () #

new :: BloomSize -> ST s (MBloom s a) Source #

Create a new mutable Bloom filter.

The filter size is capped at maxSizeBits.

maxSizeBits :: Int Source #

The maximum filter size is $2^48$ bits. Tell us if you need bigger bloom filters.

Immutable Bloom filters

data Bloom a Source #

An immutable Bloom filter.

Instances

Instances details
Show (Bloom a) Source # 
Instance details

Defined in Data.BloomFilter.Classic.Internal

Methods

showsPrec :: Int -> Bloom a -> ShowS #

show :: Bloom a -> String #

showList :: [Bloom a] -> ShowS #

NFData (Bloom a) Source # 
Instance details

Defined in Data.BloomFilter.Classic.Internal

Methods

rnf :: Bloom a -> () #

Eq (Bloom a) Source # 
Instance details

Defined in Data.BloomFilter.Classic.Internal

Methods

(==) :: Bloom a -> Bloom a -> Bool #

(/=) :: Bloom a -> Bloom a -> Bool #

size :: Bloom a -> BloomSize Source #

Return the size of the Bloom filter.

Hash-based operations

data Hashes a Source #

A pair of hashes used for a double hashing scheme.

See evalHashes.

hashes :: Hashable a => a -> Hashes a Source #

Create Hashes structure.

It's simply hashes the value twice using seed 0 and 1.

insertHashes :: MBloom s a -> Hashes a -> ST s () Source #

elemHashes :: Bloom a -> Hashes a -> Bool Source #

Query an immutable Bloom filter for membership using already constructed Hashes value.

readHashes :: forall s a. MBloom s a -> Hashes a -> ST s Bool Source #

Conversion

freeze :: MBloom s a -> ST s (Bloom a) Source #

Create an immutable Bloom filter from a mutable one. The mutable filter may be modified afterwards.

unsafeFreeze :: MBloom s a -> ST s (Bloom a) Source #

Create an immutable Bloom filter from a mutable one without copying. The mutable filter must not be modified afterwards. For a safer creation interface, use freeze or create.

thaw :: Bloom a -> ST s (MBloom s a) Source #

Copy an immutable Bloom filter to create a mutable one. There is no non-copying equivalent.

(De)Serialisation

formatVersion :: Int Source #

The version of the format used by serialise and deserialise. The format number will change when there is an incompatible change in the library, such that deserialising and using the filter will not work. This can include more than just changes to the serialised format, for example changes to hash functions or how the hash is mapped to bits.

Note that the format produced does not include this version. Version checking is the responsibility of the user of the library.

The library guarantes that the format version value for the classic (Data.BloomFilter.Classic) and blocked (Data.BloomFilter.Blocked) implementation will not overlap with each other or any previous value used by either implementation. So switching between the two implementations will always be detectable and unambigious.

History:

  • Version 0: original
  • Version 1: changed range reduction (of hash to bit index) from remainder to method based on multiplication.

serialise :: Bloom a -> (BloomSize, ByteArray, Int, Int) Source #

Serialise the bloom filter to a BloomSize (which is needed to deserialise) and a ByteArray along with the offset and length containing the filter's bit data.

See also formatVersion for compatibility advice.

deserialise :: PrimMonad m => MBloom (PrimState m) a -> (MutableByteArray (PrimState m) -> Int -> Int -> m ()) -> m () Source #

Overwrite the filter's bit array. Use new to create a filter of the expected size and then use this function to fill in the bit data.

The callback is expected to write (exactly) the given number of bytes into the given byte array buffer.

See also formatVersion for compatibility advice.