Algorithm Search⌘K

Proofs: Quotient filter

These are the human proofs of Quotient filter, at full length.

The false positive rate and the cost of a quotient filter full

This proof shows: complexity.

Model. Assume ideal hashing: for a key x∉Sx \notin S, the fingerprint F(x)F(x) is uniform on {0,…,2q+r−1}\{0, \ldots, 2^{q+r} - 1\} and independent of the fingerprints of the keys of SS. Let nn be the number of distinct fingerprints stored, at most ∣S∣|S|, and α=n/2q\alpha = n/2^q.

Theorem 1. For each x∉Sx \notin S, Pr⁡[QUERY(x)=true]≤n/2q+r=α2−r\Pr[\text{QUERY}(x) = \text{true}] \le n/2^{q+r} = \alpha 2^{-r}.

Proof. By Theorem 1 of the correctness proof, QUERY(x)(x) is true exactly when F(x)F(x) is one of the stored fingerprints. Fix the stored fingerprints; there are at most nn distinct values, and F(x)F(x) hits each with probability 2−(q+r)2^{-(q+r)}. The union bound gives the claim. □\square

Theorem 2 (cost). Let CC be the number of slots of the cluster that contains slot fq(x)f_q(x), or 1 if that slot is empty. Then QUERY, INSERT and DELETE of xx take O(C)O(C) time on the word RAM, and the table takes 2q(r+3)2^q (r + 3) bits.

Proof. Line L2 moves left inside the cluster, and lines L4 to L10 move bb and ss right inside the cluster, so the query reads at most 3C3C slots. Lines L11 to L17 read and write the slots from bb to the empty slot after the cluster, at most C+1C + 1 of them, and sorting EE is not needed when it is read in order, since the runs are already sorted. □\square

Cluster length. The set of non-empty slots after any sequence of operations equals the set of slots used by linear probing with hash values fqf_q of the stored fingerprints: in both, the number of used slots in each interval of slots that starts after an empty slot is determined by the quotients in it. So the cluster lengths have the law of linear probing at load α\alpha, with expected length O(1/(1−α)2)O(1/(1 - \alpha)^2) for the cluster of a random slot under ideal hashing, which this page takes from the analysis of linear probing. ■\blacksquare

A quotient filter finds each stored fingerprint full

This proof shows: correctness, invariant, termination.

All slot indices are modulo mm, and "between", "before" and "after" are taken in the cyclic order that starts at the first slot of the cluster in question. Invariant (Q) of the page is assumed in the following precise form. The stored pairs (quotient, remainder) are the multiset Φ\Phi of the fingerprints of SS. Each cluster, with first slot cc and slots c,c+1,…,e−1c, c+1, \ldots, e - 1 before the empty slot ee, is split into runs [s0,s1),[s1,s2),…,[st−1,st)[s_0, s_1), [s_1, s_2), \ldots, [s_{t-1}, s_t) with s0=cs_0 = c and st=es_t = e. The occupied slots among c,…,e−1c, \ldots, e-1 are Q0=c<Q1<⋯<Qt−1Q_0 = c < Q_1 < \cdots < Q_{t-1}, run kk holds the remainders of quotient QkQ_k in sorted order, and Qk≤skQ_k \le s_k. The first slot of a run has continuation = 0 and the others have 1, shifted[p] = 1 exactly when slot pp holds a remainder whose quotient is not pp, and empty slots have all three bits 0.

Lemma 1. If occupied[Q] = 1, then slot QQ is non-empty and lies in the cluster that holds the run of QQ.

Proof. occupied[Q] = 1 only for a slot Q=QkQ = Q_k of some cluster, by the form of the invariant. □\square

Lemma 2. If slot pp is non-empty and shifted[p] = 0, then p=Qk=skp = Q_k = s_k for some run kk of its cluster.

Proof. Slot pp lies in some run kk, so it holds a remainder of quotient QkQ_k, and shifted[p] = 0 gives Qk=pQ_k = p. The run starts at sk≥Qk=ps_k \ge Q_k = p and contains pp, so sk≤ps_k \le p. □\square

Lemma 3 (line L2). If occupied[f_q] = 1, the loop of line L2 ends at a slot bb of the cluster of fqf_q, at or before fqf_q, with b=Qj=sjb = Q_j = s_j for some jj.

Proof. By Lemma 1 the walk starts at a non-empty slot of the cluster. If shifted[p] = 1, then pp is not the first slot cc of the cluster, since c=s0=Q0c = s_0 = Q_0 holds a remainder of quotient cc. So p−1p - 1 is in the same cluster. The walk moves left inside the cluster and stops at the latest at cc, which is unshifted. Lemma 2 gives the form of bb. □\square

Lemma 4 (lines L4 to L6). Let fq=Qlf_q = Q_l. The loop keeps b=Qib = Q_i and s=sis = s_i for some i≤li \le l, and ends with i=li = l.

Proof. By Lemma 3 this holds at the start with i=j≤li = j \le l. Suppose b=Qi≠fqb = Q_i \ne f_q, so i<li < l. Line L5 moves ss to the next slot with continuation = 0. The slots si+1,…,si+1−1s_i + 1, \ldots, s_{i+1} - 1 are continuations of run ii, and si+1s_{i+1} is the first slot of run i+1i + 1, which exists since i+1≤l<ti + 1 \le l < t; so ss becomes si+1s_{i+1}. Line L6 moves bb to the next occupied slot, which is Qi+1Q_{i+1}, because no slot strictly between QiQ_i and Qi+1Q_{i+1} is occupied. So the claim holds for i+1i + 1. The index ii grows by 1 in each round and is at most ll, so the loop ends, with i=li = l. □\square

Theorem 1 (query). QUERY(x)(x) returns true exactly when the fingerprint (fq,fr)(f_q, f_r) of xx is in Φ\Phi. So it returns true for each key of SS, and each query ends.

Proof. If occupied[f_q] = 0, no stored pair has quotient fqf_q and line L1 returns false. Otherwise, by Lemma 4, lines L7 to L10 start at sls_l, the first slot of the run of fqf_q. They read slots sl,sl+1,…s_l, s_l + 1, \ldots and stop at the first later slot with continuation = 0, which is sl+1s_{l+1}, either the start of the next run or the empty slot ee. So they compare frf_r with exactly the remainders of quotient fqf_q. □\square

Lemma 5 (decoding). Let b=Qj=sjb = Q_j = s_j in a cluster ending before the empty slot ee. The slots b,…,e−1b, \ldots, e - 1 hold exactly the runs j,…,t−1j, \ldots, t - 1, and the occupied slots among them are Qj,…,Qt−1Q_j, \ldots, Q_{t-1}, in the same order. No run of another quotient, and no other occupied bit, lies in these slots.

Proof. The runs are consecutive and sj=bs_j = b, st=es_t = e. The occupied slots of the cluster from bb on are Qj,…,Qt−1Q_j, \ldots, Q_{t-1}, because Qj=bQ_j = b and the QkQ_k increase. □\square

So line L12 reads back the pairs of runs jj to t−1t - 1: the kk-th slot with continuation = 0 from bb starts the run of the kk-th occupied slot from bb.

Theorem 2 (insert and delete keep the invariant). Assume at most m−2m - 2 stored fingerprints before an insert. After INSERT(x)(x) the stored multiset is Φ+{F(x)}\Phi + \{F(x)\}, and after DELETE(x)(x) for a present fingerprint it is Φ−{F(x)}\Phi - \{F(x)\}, and in both cases the invariant holds.

Proof. Let bb be the slot of line L11 or L15. If slot fqf_q is empty, then b=fqb = f_q and EE is empty. Otherwise slot fqf_q is non-empty, and by the argument of Lemma 3 the walk ends at a slot b=Qj=sjb = Q_j = s_j of the same cluster, at or before fqf_q; by Lemma 5 the list EE is the multiset of the pairs stored in slots bb to e−1e - 1, and all their quotients are between bb and e−1e - 1. In both cases fqf_q is between bb and ee.

Line L14 or L17 clears the old slots b,…,e−1b, \ldots, e - 1 and writes the new list E′E' greedily: the runs in increasing order of quotient, from bb, each run at the later of its quotient and the slot after the previous run, with the bits set as in the invariant. The pairs outside [b,e)[b, e) are unchanged, so the stored multiset changes by exactly the added or removed pair.

The new runs stay in place. For a delete, removing a pair moves each greedy run start left or leaves it, so the new runs lie inside [b,e)[b, e). For an insert, adding one pair moves each greedy run start right by at most 1, so the new runs lie inside [b,e][b, e]. Slot ee was empty, and the slot after it either is empty or starts a cluster whose first run starts at its own quotient; neither changes, so no two runs overlap. There is still an empty slot, since at most m−1m - 1 pairs are stored.

The invariant holds. Runs before bb end before bb and are unchanged. In the rewritten area, the greedy rule puts each run at or after its quotient and right after the previous run unless there is a gap; after a gap, the run starts at its own quotient, which makes it the first run of a new cluster with s0=Q0s_0 = Q_0. If the area now ends at ee and touches the next cluster, the two join; the runs of the next cluster start at or after their quotients and follow in increasing order, so the joined cluster satisfies the invariant. The occupied bits of the slots b,…,eb, \ldots, e are rewritten from E′E', and by Lemma 5 no other quotient had its occupied bit there. ■\blacksquare

Back to Quotient filter