BloomFilter

class BloomFilter<T>

A BloomFilter is a conservative, probabilistic set. It can report that an element is probably in the set, or definitely not in the set. This can be a useful, fast prefilter to avoid computing or fetching authoritative data in a large majority of cases, effectively reducing the number of spurious occurrences of the slower activity by orders of magnitude.

Since the filter is probabilistic, the interface is defined entirely in terms of Ints, under the assumption that the actual entity being tested for membership has already been hashed.

Author

Mark van Gulik

Parameters

T

The type of objects hashed into the filter.

Constructors

Link copied to clipboard
constructor(bitCount: Int, hashCount: Int)

Construct a new instance that initially reports false for every membership test. If a non-null existingFilter is provided, it is copied instead.

constructor(existingFilter: BloomFilter<T>)

Copy an existing BloomFilter.

constructor(binaryStream: DataInputStream)

Reconstruct a BloomFilter previously written by write.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The number of bit positions in the filter.

Functions

Link copied to clipboard
fun add(element: T)

Add an element (T) to the filter.

Link copied to clipboard
fun addAll(filter: BloomFilter<T>)

Add all elements of the given BloomFilter to the receiver. The array size and hashCount of the given filter should match that of the receiver.

Link copied to clipboard
fun addHash(elementHash: Int)

Add an Int, the hashCode of some element, to the BloomFilter.

Link copied to clipboard
operator fun get(element: T): Boolean

Determine whether the given element is probably present in the filter. If the element is present, this always returns true, but it may sometimes return true even if the element is not present.

Link copied to clipboard
fun getByHash(elementHash: Int): Boolean

Determine whether an element with the given hashCode is probably present in the filter. If the element is present, this always returns true, but it may sometimes return true even if the element is not present.

Link copied to clipboard
fun write(binaryStream: DataOutputStream)

Write this BloomFilter onto the given stream, such that the constructor taking a DataInputStream can reconstruct it.