| 2 Comments | No TrackBacks

Since I thought a Bloom filter might be to blame in Mac OS X’s spellchecker, I made a little Processing app to demonstrate how exactly a Bloom filter works.

First, a brief description of what Bloom filters are. They’re a data structure that relies on hash functions for representing a set. The actual structure is a bunch of bits and a few hash functions. To add an element to a Bloom filter, compute the hashes for each hash function, and set each bit high. To test if an element has been added to the Bloom filter, compute the hashes and return true if all the bits are already high. A quick overview of what this means:


  • You don’t store any elements in the Bloom filter—just the elements’ hashes. Very compact.
  • Lookup and adding to the set are extremely fast.
  • Union and intersection of Bloom filter sets are just bitwise operators.


  • False positives are possible. (Since we don’t store the actual elements, we might see all the hashed bits as high when it was actually one or more previously added elements that made them high.)
  • There’s no way to remove an element from the set. (We don’t know if another element has hashed to the bits we want to set low.)

Without further ado, here’s the app. (It’s a little rough around the edges, and, yes, it’s a Java applet—Processing.js has a few bugs and is slow as balls for this type of application, apparently.) This is a Bloom filter with 625 bits and 10 hash functions. (More implementation details below.) Have fun—ask questions or leave feedback in the comments!


  1. Give the applet focus by clicking on the dots.
  2. Start typing into it and you’ll see the bits your string is hashing to in real time.
  3. Hit enter to add the string and you’ll see the high bits turn red. Repeat!
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 
        width="500" height="550"
        standby="Loading Processing software..."  >

    <param name="code" value="bloom" />
    <param name="archive" value="/files/processing/bloom.jar" />

    <param name="mayscript" value="true" />
    <param name="scriptable" value="true" />

    <param name="image" value="loading.gif" />
    <param name="boxmessage" value="Loading Processing software..." />
    <param name="boxbgcolor" value="#FFFFFF" />

    <param name="test_string" value="inner" />

            This browser does not have a Java Plug-in.
            <br />
            <a href="" title="Download Java Plug-in">
                Get the latest Java Plug-in here.


For those curious, to get my ten hash functions, I’m double hashing two string hash functions I found: djb2 and sdbm.

For the even more curious, here’s the Processing source.

Update: Added more explicit directions.

No TrackBacks

TrackBack URL:


i love the pulsating bits i was confused that i was supposed to press [enter]. i skipped the directions apparently
Very nice, bloom filters are such a neat data structure, if not so useful