Proofs: Xor filter
These are the human proofs of Xor filter, at full length.
The false positive rate of an xor filter full
This proof shows: complexity.
Model. Assume ideal hashing: in each try, and are independent random functions, with uniform on block and uniform on , and the tries use independent functions.
Theorem 1. For each key , .
Proof. Let be the try at which BUILD stops. Whether a try succeeds depends only on the cells of the keys of in that try, so is independent of the values at of the functions of all tries. The table is a function of the cells and fingerprints of the keys of in try . Given and all the values on , the values of try are still independent and uniform, since . So the xor is independent of , and
Theorem 2 (time and space). QUERY takes time: four hash values and three cell reads. Each try of BUILD takes time, which is . The table has bits, with .
Proof. Lines L6 and L7 visit each key and each cell once. In lines L8 and L9 each cell enters the queue at most once at line L7 and once for each time its count falls to 1, which is at most once for each key that uses it, so the queue has at most entries in total, and each is handled in constant time. The loop of lines L4 and L5 has steps of constant time. The bound on follows from . With Theorem 2 of the correctness proof, the expected time of BUILD is , which is whenever the success probability of a try is bounded below by a constant, as it is at this table size for large by the threshold result of Molloy (2005).
An xor filter accepts every key of its set full
This proof shows: correctness, invariant, termination.
Let be a set of distinct keys. For fixed hash functions write , a set of three distinct cells, one in each block.
Lemma 1 (peeling order). If PEEL succeeds, its order lists each key of once, and for each , and for each .
Proof. Call a key remaining while it is not yet in the order. Lines L6 and L9 keep, for each cell , the count and the xor of the indices of the remaining keys with : line L6 sets them for all keys, and line L9 removes a key from its three cells when it leaves. When line L8 takes a cell with count 1, exactly one remaining key uses , and the xor is its index. That key is appended and stops being remaining. So , each key is appended at most once, and the keys with were remaining at that time and are not , so they do not use . Success at line L10 means all keys are listed.
Lemma 2. In the loop of lines L4 and L5, the cell is written only at step , and after step no cell of is written.
Proof. Step writes only . For , by Lemma 1, while , so . The steps after step are the steps , and they write , which is not in by Lemma 1 applied to and the later index .
Theorem 1 (invariant (X) and no false negatives). After BUILD, for each , so QUERY returns true.
Proof. Take , and let be the two cells of other than . Line L5 sets , so right after step , , since . By Lemma 2 none of the three cells changes after step . Line L11 then computes the same xor.
Theorem 2 (termination). Under ideal hashing, with a fresh independent choice of hash functions in each try, BUILD ends with probability 1, and the number of tries has a geometric distribution.
Proof. Each try succeeds with the same probability , independently. It remains to show , by one choice of the cells that peels. Since , we have , so we can give each key a private cell , all distinct, using at most cells of each block, and keep one spare cell in each block . Let the other two cells of be the spare cells of the two other blocks. Then each has count 1 and is in the first queue, and peeling removes the keys one after another, so it succeeds. This choice of cells has positive probability under ideal hashing. Each try is steps, since each key leaves the queue at most once.