Class BloomFilter<E>

java.lang.Object
org.drasyl.util.BloomFilter<E>
Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
CountingBloomFilter

public class BloomFilter<E> extends Object implements Set<E>
A bloom filter is a probabilistic data structure that can quickly and efficiently check whether an element is included in a set.

This implementation uses Murmur3.murmur3_x86_32 as hash source is backed by a BitSet.

Although this class implements Set, not all set operations are actually supported (e.g. removal or retrieval of elements).

  • Field Details

  • Constructor Details

    • BloomFilter

      protected BloomFilter(BloomFilter.Parameters parameters, Function<E,byte[]> bytesSupplier, BitSet bitSet)
    • BloomFilter

      protected BloomFilter(BloomFilter.Parameters parameters, Function<E,byte[]> bytesSupplier)
    • BloomFilter

      public BloomFilter(int n, double p, int m, int k, Function<E,byte[]> bytesSupplier, BitSet bitSet)
      Create a new bloom filter. Make sure to leave one parameter 0 as it must be derived from the other parameters.

      Visit Bloom Filter Calculator to get more information about the implications/calculation of these parameters.

      If m is not a multiple of MurmurHash3 x86 32-bit hash, this bloom filter is subject of the "modulo bias" effect.

      Parameters:
      n - Number of items in the filter. If 0, this value is derived from p, m, and k
      p - Probability of false positives, fraction between 0 and 1. If 0, this value is derived from n, m, and k
      m - Number of bits in the filter. If 0, this value is derived from n and p
      k - Number of hash functions. If 0, this value is derived from m and n
      bytesSupplier - a Function that convert objects of type E to byte[] arrays
      bitSet - BitSet holding this bloom filter's state. Caller must ensure that it has the correct size.
      Throws:
      IllegalArgumentException - if one parameter is not 0 or p is not between 0 and 1
      NullPointerException - if bytesSupplier is null
    • BloomFilter

      public BloomFilter(int n, double p, int m, int k, Function<E,byte[]> bytesSupplier)
      Create a new bloom filter. Make sure to leave one parameter 0 as it must be derived from the other parameters.

      Visit Bloom Filter Calculator to get more information about the implications/calculation of these parameters.

      If m is not a multiple of MurmurHash3 x86 32-bit hash, this bloom filter is subject of the "modulo bias" effect.

      Parameters:
      n - Number of items in the filter. If 0, this value is derived from p, m, and k
      p - Probability of false positives, fraction between 0 and 1. If 0, this value is derived from n, m, and k
      m - Number of bits in the filter. If 0, this value is derived from n and p
      k - Number of hash functions. If 0, this value is derived from m and n
      bytesSupplier - a Function that convert objects of type E to byte[] arrays
      Throws:
      IllegalArgumentException - if one parameter is not 0 or p is not between 0 and 1
      NullPointerException - if bytesSupplier is null
    • BloomFilter

      public BloomFilter(Integer n, Double p, Function<E,byte[]> bytesSupplier, BitSet bitSet)
      Create a new bloom filter. Make sure to leave one parameter 0 as it must be derived from the other parameters.

      Visit Bloom Filter Calculator to get more information about the implications/calculation of these parameters.

      Parameters:
      n - Number of items in the filter
      p - Probability of false positives, fraction between 0 and 1
      bytesSupplier - a Function that convert objects of type E to byte[] arrays
      bitSet - BitSet holding this bloom filter's state. Caller must ensure that it has the correct size.
      Throws:
      IllegalArgumentException - if n or p is 0 or p is not between 0 and 1
      NullPointerException - if bytesSupplier is null
    • BloomFilter

      public BloomFilter(Integer n, Double p, Function<E,byte[]> bytesSupplier)
      Create a new bloom filter. Make sure to leave one parameter 0 as it must be derived from the other parameters.

      Visit Bloom Filter Calculator to get more information about the implications/calculation of these parameters.

      Parameters:
      n - Number of items in the filter
      p - Probability of false positives, fraction between 0 and 1
      bytesSupplier - a Function that convert objects of type E to byte[] arrays
      Throws:
      IllegalArgumentException - if n or p is 0 or p is not between 0 and 1
      NullPointerException - if bytesSupplier is null
  • Method Details