/** * Update bloom filter with a {@code double}. */ public void put(double data) { put(Double.doubleToLongBits(data)); }
/** * Update bloom filter with a {@code float}. */ public void put(float data) { put(Float.floatToIntBits(data)); }
/** * Update bloom filter with a {@code String}. */ public void put(String data) { put(data.getBytes(StandardCharsets.UTF_8)); }
@Test public void testLong() { final BloomFilter bf = BloomFilter.bySize(nBytes); // Put longs into bloomfilter by random Random rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { bf.put(rand.nextLong()); } // Reset the rand and check existence of the keys. rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { assertTrue(bf.mayContain(rand.nextLong())); } }
@Test public void testDouble() { final BloomFilter bf = BloomFilter.bySize(nBytes); // Put doubles into bloomfilter by random Random rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { bf.put(rand.nextDouble()); } // Reset the rand and check existence of the keys. rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { assertTrue(bf.mayContain(rand.nextDouble())); } }
@Test public void testIntGenBFByCount() { final BloomFilter bf = BloomFilter.byCount(nKeys); // Put integers into bloomfilter by random Random rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { bf.put(rand.nextInt()); } // Reset the rand and check existence of the keys. rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { assertTrue(bf.mayContain(rand.nextInt())); } }
@Test public void testBoolean() { final BloomFilter bf = BloomFilter.bySize(nBytes); // Put booleans into bloomfilter by random Random rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { bf.put(rand.nextBoolean()); } // Reset the rand and check existence of the keys. rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { assertTrue(bf.mayContain(rand.nextBoolean())); } }
@Test public void testShort() { final BloomFilter bf = BloomFilter.bySize(nBytes); // Put shorts into bloomfilter by random Random rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { bf.put((short)rand.nextInt()); } // Reset the rand and check existence of the keys. rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { assertTrue(bf.mayContain((short)rand.nextInt())); } }
@Test public void testIntGenBFBySize() { final BloomFilter bf = BloomFilter.bySize(nBytes); // Put integers into bloomfilter by random Random rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { bf.put(rand.nextInt()); } // Reset the rand and check existence of the keys. rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { assertTrue(bf.mayContain(rand.nextInt())); } }
@Test public void testFloat() { final BloomFilter bf = BloomFilter.bySize(nBytes); // Put floats into bloomfilter by random Random rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { bf.put(rand.nextFloat()); } // Reset the rand and check existence of the keys. rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { assertTrue(bf.mayContain(rand.nextFloat())); } }
@Test public void testString() { final BloomFilter bf = BloomFilter.bySize(nBytes); // Put strings into bloomfilter by random Random rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { bf.put(rand.nextInt() + ""); } // Reset the rand and check existence of the keys. rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { assertTrue(bf.mayContain(rand.nextInt() + "")); } } }
@Test public void testBytes() { final BloomFilter bf = BloomFilter.bySize(nBytes); // Put byte arrays into bloomfilter by random Random rand = new Random(kRandomSeed); byte[] bytes = new byte[64]; for (int i = 0; i < nKeys; i++) { rand.nextBytes(bytes); bf.put(bytes); } // Reset the rand and check existence of the keys. rand = new Random(kRandomSeed); for (int i = 0; i < nKeys; i++) { rand.nextBytes(bytes); assertTrue(bf.mayContain(bytes)); } }