Recently used to find the duplicate elements in the list, the results to share with you, you also as a note.
The implementation of the Bloomfilter filter found on the Web:
public class Bloomfilter {private static final int default_size = 2 << 24;
private static final int[] seeds = new int[] {5, 7, 11, 13, 31, 37, 61};
Private Bitset bits = new Bitset (default_size);
Private simplehash[] func = new Simplehash[seeds.length]; Public Bloomfilter () {for (int i = 0; i < seeds.length; i++) {Func[i] = new Simplehash (default_si
ZE, Seeds[i]); } public void Add (String value) {for (Simplehash f:func) {Bits.set (F.hash (value), true)
;
} public Boolean contains (String value) {if (value = = null) {return false;
boolean ret = true;
for (Simplehash f:func) {ret = ret && bits.get (F.hash (value));
return ret;
}//Internal class, Simplehash public static class Simplehash {private int cap;
private int seed;
public Simplehash (int cap, int seed) { This.cap = cap;
This.seed = seed;
public int hash (String value) {int = 0;
int len = Value.length ();
for (int i = 0; i < len; i++) {result = Seed * result + value.charat (i);
Return (cap-1) & result; }
}
}
How to use:
public static void Main (string[] args) {
bloomfilter bf = new Bloomfilter ();
List<string> STRs = new arraylist<string> ();
Strs.add ("123456");
Strs.add ("Hello word");
Strs.add ("Transdocid");
Strs.add ("123456");
Strs.add ("Transdocid");
Strs.add ("Hello word");
Strs.add ("test");
for (int i=0;i<strs.size (); i++) {
String s = strs.get (i);
Boolean bl = Bf.contains (s);
if (BL) {
System.out.println (i+ "," +s);
} else{
Bf.add (s);
}
}