com.lmonson.hash.bloom
Class BloomFilter<T>

java.lang.Object
  extended by com.lmonson.hash.bloom.BloomFilter<T>

public class BloomFilter<T>
extends java.lang.Object

An implementation of Bloom Filters.

Creating a simple Bloom Filter

 // Two hash functions
 HashFunction h1 = new PseudoRandomHashFunction(1);
 HashFunction h2 = new PseudoRandomHashFunction(2);
 
 // Create the bloom filter in ram, 1024 bits wide
 BloomFilter filter = new BloomFilter(
                             new HashFunction[] { h1, h2 },
                             new RamBitStore(1024)
 );  
 
 // Use the bloom filter
 filter.add(1);
 filter.add(2);
 filter.contains(1);      // returns true
 filter.contains(3);      // returns false
 

Create a really big Bloom Filter, stored in a temporary file on disk

 // Two hash functions
 HashFunction h1 = new PseudoRandomHashFunction(1);
 HashFunction h2 = new PseudoRandomHashFunction(2);
 
 // Create the BitStore -- assumes you have enough RAM on your machine
 // to hold the bits in ram.  Note that this RAM comes from the system heap
 // and NOT from the JVM heap.
 BitStore bitStore = new MemoryMappedFileBitStore(Integer.MAX_VALUE);
 
 // Create the bloom filter on disk
 BloomFilter filter = new BloomFilter(
                             new HashFunction[] { h1, h2 },
                             bitStore
 );  
 
 // Use the bloom filter
 filter.add(1);
 filter.add(2);
 filter.contains(1);      // returns true
 filter.contains(3);      // returns false
 


Constructor Summary
BloomFilter(HashFunction<T>[] hashFunctions, BitStore bitStore)
           
 
Method Summary
 void add(T... objectsToHash)
           
 void add(T objectToHash)
           
 boolean contains(T t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BloomFilter

public BloomFilter(HashFunction<T>[] hashFunctions,
                   BitStore bitStore)
Method Detail

add

public void add(T objectToHash)

add

public void add(T... objectsToHash)

contains

public boolean contains(T t)