Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So I have seen this question before, and I used advice above and it turned out to be way to slow for me. So I wrote my own. It is not fully general, but I am sure if somebody is desperate for performance like I am they will make it more general by themselves :) </p> <p>I used Murmur hash implementation that you can download here: <a href="http://d3s.mff.cuni.cz/~holub/sw/javamurmurhash/" rel="nofollow">http://d3s.mff.cuni.cz/~holub/sw/javamurmurhash/</a></p> <p>The code: package uk.ac.cam.cl.ss958.SpringBoardSimulation;</p> <pre><code> import ie.ucd.murmur.MurmurHash; import java.util.BitSet; import java.util.Random; public class FastBloomFilter { private final BitSet bs; final int [] hashSeeds; final int capacity; public FastBloomFilter(int slots, int hashFunctions) { bs = new BitSet(slots); Random r = new Random(System.currentTimeMillis()); hashSeeds = new int[hashFunctions]; for (int i=0; i&lt;hashFunctions; ++i) { hashSeeds[i] = r.nextInt(); } capacity = slots; } public void add(int value) { byte [] b = new byte[] { (byte)(value &gt;&gt;&gt; 24), (byte)(value &gt;&gt;&gt; 16), (byte)(value &gt;&gt;&gt; 8), (byte)value}; for (int i=0; i&lt;hashSeeds.length; ++i) { int h = MurmurHash.hash32(b, 4, hashSeeds[i]); bs.set(Math.abs(h)%capacity, true); } } public void clear() { bs.clear(); } public boolean mightContain(int value) { byte [] b = new byte[] { (byte)(value &gt;&gt;&gt; 24), (byte)(value &gt;&gt;&gt; 16), (byte)(value &gt;&gt;&gt; 8), (byte)value}; for (int i=0; i&lt;hashSeeds.length; ++i) { int h = MurmurHash.hash32(b, 4, hashSeeds[i]); if(!bs.get(Math.abs(h)%capacity)) { return false; } return true; } public static void main(String [] args) { FastBloomFilter bf = new FastBloomFilter(1000, 10); System.out.println("Query for 2000: " + bf.mightContain(2000)); System.out.println("Adding 2000"); bf.add(2000); System.out.println("Query for 2000: " + bf.mightContain(2000)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload