Bloom filter
A tiny bit array that answers “definitely not in the set” or “probably in the set”, used to skip expensive lookups.
A Bloom filter sets a few bits for every item it stores, chosen by several hash functions. To check an item, you look at its bits: if any is zero, the item was never added; if all are one, it probably was, but the bits may have been set by other items. There are false positives but no false negatives. Burton Bloom described it in 1970.
The point is space. A filter for millions of keys fits in a few megabytes, and you choose the false-positive rate by giving it more or fewer bits per item. It sits in front of anything slow: LSM tree databases keep one per file to avoid reading files that cannot contain a key, caches use one to skip lookups for keys never stored, and crawlers use one to avoid fetching the same URL twice.
A plain Bloom filter cannot delete items and cannot list them; it only answers membership. Counting variants and cuckoo filters add deletion at some cost in space.
Sources
- Communications of the ACM: Bloom, Space/Time Trade-offs in Hash Coding with Allowable Errors (1970) doi.org
Related terms
- LSM tree (log-structured merge tree): A storage design that buffers writes in memory and flushes them as sorted files merged in the background; fast writes, more work on reads.
- Hash table: A structure that finds a value by its key in about constant time by hashing the key into a slot; fast lookups, no order.
- Count-min sketch: A small table of counters that estimates how often each item appears in a stream; it may overcount but never undercounts.
- HyperLogLog: A tiny sketch that estimates how many distinct items a stream has, such as unique visitors, with a small known error and fixed memory.
- Cryptographic hash function (SHA-256): A function that turns any data into a short fixed-size fingerprint that is practically impossible to reverse or to match with different data.
