CountingBloomFilter extends AbstractFilter { @Override public void add(Key key) { if(key == null) { throw new NullPointerException("key can not be null"); } int[] h = hash.hash(key); hash.clear(); for(int i = 0; i < nbHash; i++) { int wordNum = h[i] >> 4; int bucketShift = (h[i] & 0x0f) << 2; long bucketMask = 15L << bucketShift; long bucketValue = (buckets[wordNum] & bucketMask) >>> bucketShift; if(bucketValue < BUCKET_MAX_VALUE) { buckets[wordNum] = (buckets[wordNum] & ~bucketMask) | ((bucketValue + 1) << bucketShift); } } } CountingBloomFilter();  CountingBloomFilter(int vectorSize, int nbHash, int hashType); @Override void add(Key key); void delete(Key key); @Override void and(AbstractFilter filter); @Override boolean membershipTest(Key key); int estimateCount(Key key); @Override void not(); @Override void or(AbstractFilter filter); @Override void xor(AbstractFilter filter); @Override String toString(); @Override void write(DataOutput out); @Override void readFields(DataInput in);  }
@Test public void testAdd() { System.out.println("add"); Random r = new Random(); CountingBloomFilter instance = new CountingBloomFilter(10000, 32, Hash.MURMUR_HASH); Map<Integer, Integer> count = new HashMap<Integer, Integer>(1000); for (int i=0; i<1000; i++) { int num = r.nextInt(10); Key k = new Key(String.valueOf(num).getBytes()); instance.add(k); int c = 1; if (count.containsKey(num)) c = c + count.get(num); count.put(num, c); } System.out.println("Num\tEst.\tActual"); for (int i=0; i<10; i++) { Key k = new Key(String.valueOf(i).getBytes()); System.out.println(i + "\t" + instance.estimateCount(k) + "\t" + count.get(i)); } }