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

Data.BloomFilter.Mutable

Description

A fast, space efficient Bloom filter implementation. A Bloom filter is a set-like data structure that provides a probabilistic membership test.

  • Queries do not give false negatives. When an element is added to a filter, a subsequent membership test will definitely return True.
  • False positives are possible. If an element has not been added to a filter, a membership test may nevertheless indicate that the element is present.

This module provides low-level control. For an easier to use interface, see the Data.BloomFilter.Easy module.

Synopsis

Overview

Each of the functions for creating Bloom filters accepts two parameters:

  • The number of bits that should be used for the filter. Note that a filter is fixed in size; it cannot be resized after creation.
  • A number of hash functions, k, to be used for the filter.

By choosing these parameters with care, it is possible to tune for a particular false positive rate. The suggestSizing function in the Data.BloomFilter.Easy module calculates useful estimates for these parameters.

Ease of use

This module provides both mutable interfaces for creating and querying a Bloom filter. It is most useful as a low-level way to manage a Bloom filter with a custom set of characteristics.

Performance

The implementation has been carefully tuned for high performance and low space consumption.

Types

type Hash = Word64 Source #

A hash value is 64 bits wide.

type MBloom s = MBloom' s CheapHashes Source #

Mutable Bloom filter using CheapHashes hashing scheme.

data MBloom' s h a Source #

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

Instances

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

Defined in Data.BloomFilter.Mutable.Internal

Methods

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

show :: MBloom' s h a -> String #

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

data RealHashes a Source #

A closure of real hashing function.

Instances

Instances details
Hashes (RealHashes :: Type -> Type) Source # 
Instance details

Defined in Data.BloomFilter.Hash

Mutable Bloom filters

Creation

new Source #

Arguments

:: Int

number of hash functions to use

-> Word64

number of bits in filter

-> ST s (MBloom' s h a) 

Create a new mutable Bloom filter.

The size is ceiled at $2^48$. Tell us if you need bigger bloom filters.

Accessors

length :: MBloom' s h a -> Word64 Source #

Return the size of a mutable Bloom filter, in bits.

elem :: (Hashes h, Hashable a) => a -> MBloom' s h a -> ST s Bool Source #

Query a mutable Bloom filter for membership. If the value is present, return True. If the value is not present, there is still some possibility that True will be returned.

Mutation

insert :: (Hashes h, Hashable a) => MBloom' s h a -> a -> ST s () Source #

Insert a value into a mutable Bloom filter. Afterwards, a membership query for the same value is guaranteed to return True.