Example usage for com.google.common.hash Funnel funnel

List of usage examples for com.google.common.hash Funnel funnel

Introduction

In this page you can find the example usage for com.google.common.hash Funnel funnel.

Prototype

funnel

Source Link

Usage

From source file:com.jordanwilliams.heftydb.test.performance.table.file.TableBloomFilterPerformance.java

public static void main(String[] args) throws Exception {
    TestFileHelper.createTestDirectory();
    KeyValueGenerator keyValueGenerator = new KeyValueGenerator();
    Value value = new Value(keyValueGenerator.testValue(100));

    System.out.println("Writing bloom filter");

    Paths paths = ConfigGenerator.testPaths();
    TableBloomFilterWriter filterWriter = TableBloomFilterWriter.open(1, paths, RECORD_COUNT);
    BloomFilter<Key> guavaFilter = BloomFilter.create(new Funnel<Key>() {
        @Override/*from w w  w .j a  v  a 2s.c o  m*/
        public void funnel(Key key, PrimitiveSink primitiveSink) {
            primitiveSink.putBytes(key.data().array());
        }
    }, RECORD_COUNT, 0.01);

    for (int i = 0; i < RECORD_COUNT; i++) {
        value.data().rewind();
        filterWriter.write(new Key(ByteBuffers.fromString(i + ""), i));
        guavaFilter.put(new Key(ByteBuffers.fromString(i + ""), i));
    }

    filterWriter.finish();

    System.out.println("Reading bloom filter");

    TableBloomFilter tableBloomFilter = TableBloomFilter.read(1, paths);

    double hits = 0;
    double misses = 0;

    double ghits = 0;
    double gmisses = 0;

    for (int i = RECORD_COUNT * 2; i > RECORD_COUNT; i--) {
        if (tableBloomFilter.mightContain(new Key(ByteBuffers.fromString(i + ""), i))) {
            hits++;
        } else {
            misses++;
        }

        if (guavaFilter.mightContain(new Key(ByteBuffers.fromString(i + ""), i))) {
            ghits++;
        } else {
            gmisses++;
        }
    }

    System.out.println("False positive rate: " + hits / (hits + misses));
    System.out.println("Guava positive rate: " + ghits / (ghits + gmisses));

    TestFileHelper.cleanUpTestFiles();
}

From source file:fr.tse.fi2.hpp.labs.queries.impl.lab5.BloomGuava.java

public BloomGuava(QueryProcessorMeasure measure) {
    super(measure);
    // TODO Auto-generated constructor stub

    Funnel<DebsRecord> recordFunnel = new Funnel<DebsRecord>() {
        @Override//ww  w  .  j a v  a2 s  .co  m
        public void funnel(DebsRecord record, PrimitiveSink into) {
            into.putString(record.getHack_license(), Charsets.UTF_8).putFloat(record.getPickup_longitude())
                    .putFloat(record.getPickup_latitude()).putFloat(record.getDropoff_longitude())
                    .putFloat(record.getDropoff_latitude());
        }
    };

    //BloomFilter<DebsRecord> filtre = new BloomFilter.create(recordFunnel,1000,0.01);

}

From source file:org.largecollections.FastIntIntCacheMap.java

private void initializeBloomFilter() {
    this.myFunnel = new Funnel<Integer>() {
        public void funnel(Integer obj, PrimitiveSink into) {
            into.putInt(Math.abs(obj.hashCode()));

        }// w w w. j  a  v  a2s. com
    };
    this.bloomFilter = BloomFilter.create(myFunnel, this.bloomFilterSize);
}

From source file:org.largecollections.CacheSetWithUnqToString.java

private void initializeBloomFilter() {
    this.myFunnel = new Funnel<String>() {
        public void funnel(String obj, PrimitiveSink into) {
            into.putString(obj);/*from  w  w w  .j  a va  2  s.  co m*/

        }
    };
    this.bloomFilter = BloomFilter.create(myFunnel, this.bloomFilterSize);
}

From source file:org.largecollections.CacheSetWithUnqHashCode.java

private void initializeBloomFilter() {
    this.myFunnel = new Funnel<Integer>() {
        public void funnel(Integer obj, PrimitiveSink into) {
            into.putInt(obj);//from   w  w w  .  j a  v a 2  s .  com

        }
    };
    this.bloomFilter = BloomFilter.create(myFunnel, this.bloomFilterSize);
}

From source file:pt.haslab.dude.FileInfo.java

public FileInfo(String name, List<FileInfo> bigger, Polynomial polynomial, boolean detail, int minchunk,
        int minshare) {
    this.name = name;
    this.polynomial = polynomial;
    this.detail = detail;
    this.minchunk = minchunk;
    this.minshare = minshare;
    this.seq = bigger.size() + 1;

    stats = new AliasInfo[bigger.size()];
    for (int i = 0; i < stats.length; i++)
        stats[i] = new AliasInfo(bigger.get(i));

    bloom = BloomFilter.create(new Funnel<String>() {
        public void funnel(String arg0, PrimitiveSink arg1) {
            arg1.putString(arg0);// ww w  .j  a  v a 2  s . co  m
        }
    }, 1000000);
}

From source file:com.tw.go.sample.descriptorhash.DescriptorHash.java

private Funnel<List<String>> targetOsFunnel() {
    return new Funnel<List<String>>() {
        @Override/*from   w w  w. j  av  a 2  s  . co m*/
        public void funnel(List<String> targetOs, PrimitiveSink sink) {
            for (String os : targetOs) {
                sink.putString(os);
            }
        }
    };
}

From source file:com.axiomine.largecollections.util.LargeCollection.java

protected void initializeBloomFilter() {
    this.myFunnel = new Funnel() {
        public void funnel(Object obj, PrimitiveSink into) {
            into.putInt(obj.hashCode());
        }/*from w  ww .j  av a 2s  .  c om*/
    };
    float defaultFalsePositives = 0.03f;
    if (!StringUtils.isBlank(System.getProperty(LargeCollection.OVERRIDE_BF_FPP))) {
        String fpp = System.getProperty(LargeCollection.OVERRIDE_BF_FPP);
        try {
            float f = Float.parseFloat(fpp);
            if (f <= 0 || f > 0.2) {
                throw new RuntimeException(
                        "Bloom filter false postives probability range should be between 0 (excluded) and 0.2 (included), provided value = "
                                + f);
            } else {
                defaultFalsePositives = f;
            }
        } catch (Exception ex) {
            throw Throwables.propagate(ex);
        }
    }
    this.bloomFilter = BloomFilter.create(myFunnel, this.bloomFilterSize, defaultFalsePositives);
}

From source file:org.largecollections.MapFactory.java

private void initializeBloomFilter() {
    this.myFunnel = new Funnel<K>() {
        public void funnel(K obj, PrimitiveSink into) {
            into.putInt(Math.abs(obj.hashCode()));

        }//w  ww .  j a va 2 s  .c o m
    };
    this.bloomFilter = BloomFilter.create(myFunnel, this.bloomFilterSize);
}

From source file:com.tw.go.sample.descriptorhash.DescriptorHash.java

private Funnel<PluginDescriptor.Vendor> vendorFunnel() {
    return new Funnel<PluginDescriptor.Vendor>() {
        @Override/*w  ww.j  a v  a  2  s  .  c o  m*/
        public void funnel(PluginDescriptor.Vendor vendor, PrimitiveSink sink) {
            sink.putString(vendor.name()).putString(vendor.url());
        }
    };
}