BloomFilter

class BloomFilter

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

Constructors

Link copied to clipboard
fun BloomFilter(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.

Link copied to clipboard
fun BloomFilter(existingFilter: BloomFilter)

Copy an existing BloomFilter.

Functions

Link copied to clipboard
fun add(element: Int)

Add an Int element to the BloomFilter.

Link copied to clipboard
fun addAll(filter: BloomFilter)

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
operator fun get(element: Int): 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.