Example usage for org.apache.hadoop.util.bloom DynamicBloomFilter membershipTest

List of usage examples for org.apache.hadoop.util.bloom DynamicBloomFilter membershipTest

Introduction

In this page you can find the example usage for org.apache.hadoop.util.bloom DynamicBloomFilter membershipTest.

Prototype

@Override
    public boolean membershipTest(Key key) 

Source Link

Usage

From source file:hivemall.sketch.bloom.BloomFilterUtilsTest.java

License:Apache License

@Test
public void testDynamicBloomFilter() {
    DynamicBloomFilter dbf = BloomFilterUtils.newDynamicBloomFilter(300000);
    final Key key = new Key();

    final Random rnd1 = new Random(43L);
    for (int i = 0; i < 1000000; i++) {
        double d = rnd1.nextGaussian();
        String s = Double.toHexString(d);
        key.set(s.getBytes(), 1.0);// w  ww .  j ava2s.  co  m
        dbf.add(key);
    }

    final Random rnd2 = new Random(43L);
    for (int i = 0; i < 1000000; i++) {
        double d = rnd2.nextGaussian();
        String s = Double.toHexString(d);
        key.set(s.getBytes(), 1.0);
        Assert.assertTrue(dbf.membershipTest(key));
    }
}

From source file:hivemall.sketch.bloom.BloomFilterUtilsTest.java

License:Apache License

@Test
public void testDynamicBloomFilterSerde() throws IOException {
    final Key key = new Key();

    DynamicBloomFilter dbf1 = BloomFilterUtils.newDynamicBloomFilter(300000);
    final Random rnd1 = new Random(43L);
    for (int i = 0; i < 1000000; i++) {
        double d = rnd1.nextGaussian();
        String s = Double.toHexString(d);
        key.set(s.getBytes(), 1.0);/* w w w.  j  a  v a2 s . c  o  m*/
        dbf1.add(key);
    }

    DynamicBloomFilter dbf2 = BloomFilterUtils.deserialize(BloomFilterUtils.serialize(dbf1),
            new DynamicBloomFilter());
    final Random rnd2 = new Random(43L);
    for (int i = 0; i < 1000000; i++) {
        double d = rnd2.nextGaussian();
        String s = Double.toHexString(d);
        key.set(s.getBytes(), 1.0);
        Assert.assertTrue(dbf2.membershipTest(key));
    }
}