XOR filter
An XOR filter is a static approximate-membership structure that answers a lookup by comparing a key fingerprint with the XOR of three array entries.
For a key set S and k-bit fingerprints, the array holds floor(1.23|S|) + 32 entries in three equal ranges, one per hash function. Construction maps every key to its three slots, repeatedly peels a slot that holds exactly one key onto a stack and then assigns fingerprints in reverse order, so the three entries of each key XOR to its fingerprint. A failed peel is retried with new hash seeds. For small sets the measured success rate per attempt stayed above 0.8, and it approaches 1 for large sets. [1]
A lookup computes three hashes and reads three entries regardless of the false-positive probability, with no branches. The false-positive probability is 1/2^k, and space is about 1.23 log2(1/e) bits per key, for example 9.84 bits per key with 8-bit fingerprints and a false-positive probability of 1/256, about 0.39%. [1]
That is 23% above the lower bound of log2(1/e) bits per key. The 3-wise binary fuse variant uses three locations; the 4-wise variant uses four. For sets of at least a million keys, reach 9 bits per key with a 3-wise layout, 12.5% above the bound, or about 8.6 bits per key with a 4-wise layout that gives up some query speed. Their construction can be more than twice as fast. [3]
Relations
- related
- Binary fuse filter, Bloom filter, Ribbon filter, Sorted string table, ZOR filter, Retrieval data structure
Advantages
- About 19% of the entries stay empty, so sending an occupancy bitmap plus only the occupied entries shrinks an 8-bit filter from 9.84 to 9.23 bits per key for transmission. [1]
- The xor+ variant compresses empty entries in the last third of the array with a rank structure and uses 1.0824k + 0.5125 bits per key. [1]
Limitations
- The filter is immutable, so adding or removing a key means building a new filter from the complete key set. [1]
- At very low false-positive probabilities, around 5.6 x 10^-6, cuckoo filters at full capacity use less space. [1]
- For sets below about 20,000 keys the size advantage of binary fuse filters shrinks, and xor filters may even be slightly smaller. [3]
Citations
- Graf and Lemire. Xor Filters: Faster and Smaller Than Bloom and Cuckoo Filters. ACM JEA 25 (2020). DOI: 10.1145/3376122.
- Graf and Lemire. Binary Fuse Filters: Fast and Smaller Than Xor Filters. arXiv:2201.01174 (2022).
Further reading
Sources & caveats
- xor-paper is arXiv version 3 of the 2020 ACM Journal of Experimental Algorithmics article, read in sections 3 and 4.
- fuse-paper is arXiv version 1 of the binary fuse filter article by authors at TELUQ, University of Quebec, read in the abstract, introduction, section 3 and the space results.
- The value 0.39% is 1/2^8 = 1/256 rounded, and e in the space formulas stands for the false-positive probability.