Proofs: Counting Bloom filter
These are the human proofs of Counting Bloom filter, at full length.
Counter overflow in a counting Bloom filter full
This proof shows: complexity.
Setting. Let distinct keys be stored once each. Assume ideal hashing: the values are independent and uniform on . Let be the number of the values equal to . By invariant (C) of the correctness proof, counter can be stuck only if reached at some time, and with inserts only never falls, so it suffices to bound at the end. With deletes, the bound below applies to each set of keys that is present at some time.
Lemma. For each and each integer , .
Proof. If , then some set of of the hash values is all equal to . A fixed set of values is all equal to with probability by independence. There are sets, and the union bound gives the claim.
Theorem. If , then for each integer ,
Proof. By the bound ,
using . The union bound over the positions multiplies by .
Numbers. For the factor is , and for , the value at which a 4-bit counter sticks, it is about . The exact law of is binomial with trials and success probability , close to a Poisson law with mean , so the true tail is smaller still: the Poisson tail at mean for 16 or more is about .
Time. Each of INSERT, DELETE and QUERY makes at most hash evaluations and counter accesses, and does constant work for each, so it takes time in the worst case on the word RAM with . The array uses bits.
A counting Bloom filter has no false negatives full
This proof shows: correctness, invariant, termination.
Write for the counter array after the first operations and for the multiset of keys that are stored after them. The hash functions are fixed by line L2. For a key and a position let , the number of times uses position . Let . Assume that each DELETE is applied only when has a copy in . Each loop has rounds and each round is a constant number of steps, so each operation ends.
Lemma 1 (stuck counters stay stuck). If , then for each .
Proof. Only lines L4 and L6 write a counter, and both write only when the counter is below .
Lemma 2 (invariant (C)). For each and , either and for each , or .
Proof. By induction on . At , line L1 gives , and since . Assume the claim at and look at operation and a fixed position .
A QUERY changes neither nor . If , then by Lemma 1. So assume that and that the counter was never at .
INSERT. Then . The loop of line L4 visits position exactly times. Each visit adds 1 while the counter is below . If the counter stays below through all the visits, then , and it was never at . Otherwise it reaches at some visit, and by Lemma 1 it ends at .
DELETE. Then , and because is a multiset. The loop of line L6 visits position exactly times, and each visit subtracts 1 since the counter is below . So , and it never reaches on the way down.
Theorem. After any sequence of operations that respects the precondition of DELETE, QUERY returns true for each with a copy in . QUERY returns true exactly when for each .
Proof. Lines L7 and L8 return false at the first with , and line L9 returns true if there is none. This gives the second claim. Let have a copy in and let . Then , so . By Lemma 2 either or . So no counter of is 0, and the query returns true.
Remark (the precondition). If DELETE is applied to a with no copy in , the step of Lemma 2 fails. For example, let and share position with from alone; then DELETE sets and QUERY returns false. So the precondition cannot be removed.