@Override public boolean put(long e) { return bloomFilter.put(e); }
public void testPutAll() { int element1 = 1; int element2 = 2; BloomFilter<Integer> bf1 = BloomFilter.create(Funnels.integerFunnel(), 100); bf1.put(element1); assertTrue(bf1.mightContain(element1)); assertFalse(bf1.mightContain(element2)); BloomFilter<Integer> bf2 = BloomFilter.create(Funnels.integerFunnel(), 100); bf2.put(element2); assertFalse(bf2.mightContain(element1)); assertTrue(bf2.mightContain(element2)); assertTrue(bf1.isCompatible(bf2)); bf1.putAll(bf2); assertTrue(bf1.mightContain(element1)); assertTrue(bf1.mightContain(element2)); assertFalse(bf2.mightContain(element1)); assertTrue(bf2.mightContain(element2)); }
@Override public boolean put(String unique) { return filter.put(unique); }
@Override public void add(Object input) { _bloomFilter.put(input.toString()); }
@Override public boolean isDuplicate(Request request, Task task) { boolean isDuplicate = bloomFilter.mightContain(getUrl(request)); if (!isDuplicate) { bloomFilter.put(getUrl(request)); counter.incrementAndGet(); } return isDuplicate; }
public void testEquals() { BloomFilter<String> bf1 = BloomFilter.create(Funnels.unencodedCharsFunnel(), 100); bf1.put("1"); bf1.put("2"); BloomFilter<String> bf2 = BloomFilter.create(Funnels.unencodedCharsFunnel(), 100); bf2.put("1"); bf2.put("2"); new EqualsTester().addEqualityGroup(bf1, bf2).testEquals(); bf2.put("3"); new EqualsTester().addEqualityGroup(bf1).addEqualityGroup(bf2).testEquals(); }
public void testPutReturnValue() { for (int i = 0; i < 10; i++) { BloomFilter<String> bf = BloomFilter.create(Funnels.unencodedCharsFunnel(), 100); for (int j = 0; j < 10; j++) { String value = new Object().toString(); boolean mightContain = bf.mightContain(value); boolean put = bf.put(value); assertTrue(mightContain != put); } } }
public void testCollector() { BloomFilter<String> bf1 = BloomFilter.create(Funnels.unencodedCharsFunnel(), 100); bf1.put("1"); bf1.put("2"); assertEquals( bf1, Stream.of("1", "2") .collect(BloomFilter.toBloomFilter(Funnels.unencodedCharsFunnel(), 100))); assertEquals( bf1, Stream.of("2", "1") .collect(BloomFilter.toBloomFilter(Funnels.unencodedCharsFunnel(), 100))); }
public void testCustomSerialization() throws Exception { Funnel<byte[]> funnel = Funnels.byteArrayFunnel(); BloomFilter<byte[]> bf = BloomFilter.create(funnel, 100); for (int i = 0; i < 100; i++) { bf.put(Ints.toByteArray(i)); } ByteArrayOutputStream out = new ByteArrayOutputStream(); bf.writeTo(out); assertEquals(bf, BloomFilter.readFrom(new ByteArrayInputStream(out.toByteArray()), funnel)); }
private static void checkSanity(BloomFilter<Object> bf) { assertFalse(bf.mightContain(new Object())); assertFalse(bf.apply(new Object())); for (int i = 0; i < 100; i++) { Object o = new Object(); bf.put(o); assertTrue(bf.mightContain(o)); assertTrue(bf.apply(o)); } }
public void testExpectedFpp() { BloomFilter<Object> bf = BloomFilter.create(HashTestUtils.BAD_FUNNEL, 10, 0.03); double fpp = bf.expectedFpp(); assertEquals(0.0, fpp); // usually completed in less than 200 iterations while (fpp != 1.0) { boolean changed = bf.put(new Object()); double newFpp = bf.expectedFpp(); // if changed, the new fpp is strictly higher, otherwise it is the same assertTrue(changed ? newFpp > fpp : newFpp == fpp); fpp = newFpp; } }
bf.put(Integer.toString(i));
bf.put(Integer.toString(i));
bf.put(Integer.toString(i));
public void add(T key) { filter.put(key); }
public void testJavaSerialization() { BloomFilter<byte[]> bf = BloomFilter.create(Funnels.byteArrayFunnel(), 100); for (int i = 0; i < 10; i++) { bf.put(Ints.toByteArray(i)); } BloomFilter<byte[]> copy = SerializableTester.reserialize(bf); for (int i = 0; i < 10; i++) { assertTrue(copy.mightContain(Ints.toByteArray(i))); } assertEquals(bf.expectedFpp(), copy.expectedFpp()); SerializableTester.reserializeAndAssert(bf); }
/** * Inserts / Replaces cache element in the currently loaded page. Direct access via mapped page map * * @param key * @param value */ public void addElement(byte[] spilledValue, ImmutableBytesPtr key, byte[] value) { // put Element into map pageMap.put(key, value); // Update bloom filter bFilter.put(key.copyBytesIfNecessary()); // track current Map size to prevent Buffer overflows if (spilledValue != null) { // if previous key was present, just add the size difference totalResultSize += Math.max(0, value.length - (spilledValue.length)); } else { // Add new size information totalResultSize += (value.length + Bytes.SIZEOF_INT); } dirtyPage = true; }
/** * Inserts / Replaces cache element in the currently loaded page. Direct access via mapped page map * * @param key * @param value */ public void addElement(byte[] spilledValue, ImmutableBytesPtr key, byte[] value) { // put Element into map pageMap.put(key, value); // Update bloom filter bFilter.put(key.copyBytesIfNecessary()); // track current Map size to prevent Buffer overflows if (spilledValue != null) { // if previous key was present, just add the size difference totalResultSize += Math.max(0, value.length - (spilledValue.length)); } else { // Add new size information totalResultSize += (value.length + Bytes.SIZEOF_INT); } dirtyPage = true; }
protected void _addToBloomFilterScopeAndMetricOnly(List<ScopeAndMetricOnlySchemaRecord> records) { _logger.info("Adding {} records into scope and metric only bloom filter.", records.size()); for (ScopeAndMetricOnlySchemaRecord record : records) { String key = constructScopeAndMetricOnlyKey(record.getScope(), record.getMetric()); bloomFilterScopeAndMetricOnly.put(key); } }