Suppose most English words can be hyphenated by a few rules, but a minority need an entry from a dictionary. In his 1970 paper Bloom considered 500,000 words, of which 50,000 needed the special lookup. The problem was how to stop the other words from triggering a disk read when there was too little memory for the conventional lookup table. That is a particular workload, with many more non-members than members. [1]
One of Bloom's methods represents membership in a bit array. When adding a word, use hashes to choose positions in the array and set those bits. On a query, a zero at any selected position rules out membership. If all selected bits are set, the word is a possible member. Different words can set overlapping bits, so some words that were never added still pass to the dictionary lookup. [1][2]
Table I puts concrete numbers on the trade. The conventional comparison assumed a 2,000,000-bit hash area. A 364,000-bit configuration was expected to save 87.2% of disk accesses relative to the conventional method with a disk-resident hash area and dictionary. Those are estimates for the paper's word distribution and lookup assumptions. They are useful for seeing the scale of the choice and cannot serve as a forecast for a different workload without new measurements. [1]
The filter is allowed to waste a lookup when it says a word might be in the set. The filter cannot silently discard a real member when the same hash functions are used and inserted bits are preserved. The application therefore keeps the dictionary as the authority. As more keys fill the array, more absent keys may pass the first test. The right size depends both on how many keys enter it and what a false positive costs. [1][2]
Analysis & application
To evaluate the trade in another system, first count how often it searches for keys absent from a file and how much each needless disk read costs. Test two memory budgets on representative traffic. Measure false positives, disk reads and time spent hashing, then compare the savings with the memory taken away from other uses. Preserve an exact lookup after a possible match, especially when a wrong positive would be costly to the application. [1][3]
Apache Cassandra uses a related pattern to avoid opening every on-disk table file for a requested partition. The filter can exclude some files immediately, while files that might hold the partition are still candidates for a read. Cassandra's documentation exposes a per-table false-positive setting and describes the extra memory needed to get fewer false positives. The control is a modern expression of the original space-versus-lookup trade-off. It does not inherit Bloom's numerical result. [3]
FOLLOW THE EVIDENCE
The sources
- Space/Time Trade-offs in Hash Coding with Allowable Errors Burton H. Bloom, Communications of the ACM · jameshunt.us
- A New Analysis of the False-Positive Rate of a Bloom Filter National Institute of Standards and Technology publication archive · tsapps.nist.gov
- Bloom Filters, Cassandra 3.11 documentation Apache Cassandra project · cassandra.apache.org