Bloom filters and sketches

O(k)·O(m) bits
000000000000000000000000000000000000000000000000000000000000000000448812162024283132 countersIndex

An empty counting filter: 32 counters, all zero, and the same 3 hash functions the bit-array page uses.

An empty counting filter: 32 counters, all zero, and the same 3 hash functions the bit-array page uses.
  1. 1build the filter, but add one to a counter instead of setting a bit
  2. 2before deleting an item, check it is there: every one of its k counters must be above zero
  3. 3to delete it, subtract one from each of those k counters
  4. 4re-query every item that was inserted, and see which ones survived
Counters incremented
0
Counters decremented
0

Complexity

BestO(1)
AverageO(k)
WorstO(k)
Extra spaceO(m) bits
counters touched at n=1 predicts 1; this run took 0.

Counting Bloom filter

A counting Bloom filter replaces each bit with a small integer counter. Inserting an item adds one to its k counters; deleting it subtracts one from each. A membership query asks whether all k counters are above zero. The extra space — typically four bits per slot rather than one — buys the one operation a plain Bloom filter cannot offer at all, because clearing an item’s bits would clear bits that other items depend on.

When it is the right choice

Whenever the set changes rather than only grows: a cache summary that has to forget evicted entries, a membership set with expiry, a router’s view of its neighbours. If nothing is ever removed, the extra space is wasted and a plain bit array is the right choice.

How it works

Worth noticing

Cost

Best
O(1)
Average
O(k)
Worst
O(k)
Space
O(m) bits

Worth comparing

All probabilistic structures