Package org.apache.commons.collections4.bloomfilter

package org.apache.commons.collections4.bloomfilter
Collects extensible Bloom filter classes and interfaces.


The Bloom filter is a probabilistic data structure that indicates where things are not. Conceptually it is a bit vector. You create a Bloom filter by creating hashes and converting those to enabled bits in the vector. Multiple Bloom filters may be merged together into one Bloom filter. It is possible to test if a filter B has merged into another filter A by verifying that (A & B) == B.

Bloom filters are generally used where hash tables would be too large, or as a filter front end for longer processes. For example most browsers have a Bloom filter that is built from all known bad URLs (ones that serve up malware). When you enter a URL the browser builds a Bloom filter and checks to see if it is "in" the bad URL filter. If not the URL is good, if it matches, then the expensive lookup on a remote system is made to see if it actually is in the list. There are lots of other uses, and in most cases the reason is to perform a fast check as a gateway for a longer operation.

Some Bloom filters (e.g. CountingBloomFilter) use counters rather than bits. In this case each counter is called a cell.


The Bloom filter architecture here is designed for speed of execution, so some methods like merge, remove, add, and subtract may throw exceptions. Once an exception is thrown the state of the Bloom filter is unknown. The choice to use not use atomic transactions was made to achieve maximum performance under correct usage.

In addition the architecture is designed so that the implementation of the storage of bits is abstracted. Programs that utilize the Bloom filters may use the BitMapProducer or IndexProducer to retrieve a representation of the internal structure. Additional methods are available in the BitMap to assist in manipulation of the representations.

The Bloom filter code is an interface that requires implementation of 9 methods:

Other methods should be implemented where they can be done so more efficiently than the default implementations.


The counting Bloom filter extends the Bloom filter by counting the number of times a specific bit has been enabled or disabled. This allows the removal (opposite of merge) of Bloom filters at the expense of additional overhead.


The layered Bloom filter extends the Bloom filter by creating layers of Bloom filters that can be queried as a single Filter or as a set of filters. This adds the ability to perform windowing on streams of data.


The Shape describes the Bloom filter using the number of bits and the number of hash functions


A Hasher converts bytes into a series of integers based on a Shape. Each hasher represents one item being added to the Bloom filter.

The EnhancedDoubleHasher uses a combinatorial generation technique to create the integers. It is easily initialized by using a byte array returned by the standard MessageDigest or other hash function to initialize the Hasher. Alternatively a pair of a long values may also be used.

Other implementations of the Hasher are easy to implement, and should make use of the Hasher.Filter and/or Hasher.FileredIntConsumer classes to filter out duplicate indices when implementing Hasher.uniqueIndices(Shape).


  • Class
    A counting Bloom filter using an int array to track cells for each enabled bit.
    Contains functions to convert int indices into Bloom filter bit positions and visa versa.
    Produces bit map longs for a Bloom filter.
    The interface that describes a Bloom filter.
    Produces Bloom filters from a collection (e.g.
    Some Bloom filter implementations use a count rather than a bit flag.
    Represents an operation that accepts an <index, count> pair.
    The interface that describes a Bloom filter that associates a count with each bit index rather than a bit.
    A Hasher that implements combinatorial hashing as described by Krisch and Mitzenmacher using the enhanced double hashing technique described in the wikipedia article Double Hashing.
    A Hasher creates IndexProducer based on the hash implementation and the provided Shape.
    A convenience class for Hasher implementations to filter out duplicate indices.
    An object that produces indices of a Bloom filter.
    Layered Bloom filters are described in Zhiwang, Cen; Jungang, Xu; Jian, Sun (2010), "A multi-layer Bloom filter for duplicated URL detection", Proc.
    Implementation of the methods to manage the layers in a layered Bloom filter.
    Builder to create Layer Manager
    Static methods to create a Consumer of a LinkedList of BloomFilter perform tests on whether to reduce the collection of Bloom filters.
    A collection of common ExtendCheck implementations to test whether to extend the depth of a LayerManager.
    Represents a function that accepts a two long-valued argument and produces a binary result.
    Implementations of set operations on BitMapProducers.
    The definition of a Bloom filter shape.
    A bloom filter using an array of bit maps to track enabled bits.
    A bloom filter using a TreeSet of integers to track enabled bits.
    An abstract class to assist in implementing Bloom filter decorators.