public class MyBloomFilter {
private static final int DEFAULT_SIZE = 2 << 31 ;
private static final int[] seeds = new int [] {3,5,7,11,13,19,23,37 };
private BitSet bits = new BitSet(DEFAULT_SIZE);
private SimpleHash[] func = new SimpleHash[seeds.length];
public static void main(String[] args) {
String value = "www.xxxxx.com" ;
MyBloomFilter filter = new MyBloomFilter();
System.out.println(filter.contains(value));
System.out.println(filter.contains(value));
for ( int i = 0 ; i < seeds.length; i ++ ) {
func[i] = new SimpleHash(DEFAULT_SIZE, seeds[i]);
public void add(String value) {
for (SimpleHash f : func) {
bits.set(f.hash(value), true );
public boolean contains(String value) {
for (SimpleHash f : func) {
ret = ret && bits.get(f.hash(value));