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

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

Introduction

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

Prototype

@Override
    public void add(Key key) 

Source Link

Usage

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

License:Apache License

@Nonnull
private static DynamicBloomFilter createBloomFilter(long seed, int size) {
    DynamicBloomFilter dbf = BloomFilterUtils.newDynamicBloomFilter(3000);
    final Key key = new Key();

    final Random rnd1 = new Random(seed);
    for (int i = 0; i < size; i++) {
        double d = rnd1.nextGaussian();
        String s = Double.toHexString(d);

        key.set(s.getBytes(), 1.0);/* ww w .j ava  2 s. com*/
        dbf.add(key);
    }

    return dbf;
}

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

License:Apache License

@Nonnull
private static DynamicBloomFilter createBloomFilter(long seed, int size) {
    DynamicBloomFilter dbf = BloomFilterUtils.newDynamicBloomFilter(30);
    final Key key = new Key();

    final Random rnd1 = new Random(seed);
    for (int i = 0; i < size; i++) {
        double d = rnd1.nextGaussian();
        String s = Double.toHexString(d);
        Text t = new Text(s);
        key.set(t.getBytes(), 1.0);// w  w  w .ja v  a 2 s . c o m
        dbf.add(key);
    }

    return dbf;
}

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);//  www.j a v a2s  .  com
        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 ww .j  a  va2 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));
    }
}