package org.deuce.transaction.tl2;

import java.util.Arrays;

import org.deuce.transform.Exclude;

/**
 * Implements Bloom filter map
 * 
 * @author Guy Korland
 * @since 1.0
 *
 */
@Exclude
public class BloomFilter {

	final private static short BLOOM_FILTER_SIZE = 1 << 10; // the array length

	final private byte[] bloomFilter = new byte[BLOOM_FILTER_SIZE];


	public boolean contains( int hash) {

		int bit1 = hash & 0x3FF; // first 10 bits of the first part of the int
		int bit2 = (hash >>> Short.SIZE) & 0x3FF; // first 10 bits of the second part of the int

		return ((bloomFilter[ bit1/Byte.SIZE] & (1 << bit1%Byte.SIZE)) != 0) &&
		((bloomFilter[ bit2/Byte.SIZE] & (1 << bit2%Byte.SIZE)) != 0);
	}

	public void add( int hash) {

		int bit1 = hash & 0x3FF; // first 10 bits of the first part of the int
		int bit2 = (hash >>> Short.SIZE) & 0x3FF; // first 10 bits of the second part of the int

		bloomFilter[ bit1/Byte.SIZE] |= (1 << bit1%Byte.SIZE);
		bloomFilter[ bit2/Byte.SIZE] |= (1 << bit2%Byte.SIZE);
	}

	public void clear() {
		Arrays.fill( bloomFilter, (byte)0); // TODO check if can clear faster or even call new
	}
}

@@ -226,18 +226,19 @@
 lter %7B%0D%0A
+%09
 %0D%0A
-
 %09final p
@@ -307,25 +307,94 @@
 length%0D%0A
-%0D%0A
 %09final 
+static 
+private byte%5B%5D EMPTY_FILTER = new byte%5BBLOOM_FILTER_SIZE%5D;%0D%0A%09%0D%0A%09
 private 
@@ -446,18 +446,16 @@
 ZE%5D;%0D%0A%0D%0A
-%0D%0A
 %09public 
@@ -1155,43 +1155,8 @@
 %0D%0A%09%09
-Arrays.fill( bloomFilter, (byte)0);
  // 
@@ -1204,15 +1204,88 @@
 ll new%0D%0A
+%09%09System.arraycopy(EMPTY_FILTER, 0, bloomFilter, 0, BLOOM_FILTER_SIZE);%0D%0A
 %09%7D%0D%0A%7D%0D%0A

Improve bloomfilter clear.