Package orestes.bloomfilter

Examples of orestes.bloomfilter.FilterBuilder


        print(cbfr.contains("bison")); //true
        print(cbfr.contains("cow")); //false
    }

    public static void jsonBF() {
        BloomFilter<String> bf = new FilterBuilder().expectedElements(50).falsePositiveProbability(0.1).buildBloomFilter();
        bf.add("Ululu");
        JsonElement json = BloomFilterConverter.toJson(bf);
        print(json); //{"size":240,"hashes":4,"HashMethod":"MD5","bits":"AAAAEAAAAACAgAAAAAAAAAAAAAAQ"}
        BloomFilter<String> otherBf = BloomFilterConverter.fromJson(json);
        print(bf.contains("Ululu")); //true
View Full Code Here


        BloomFilter<String> otherBf = BloomFilterConverter.fromJson(json);
        print(bf.contains("Ululu")); //true
    }

    public static void customHash() {
        BloomFilter<String> bf = new FilterBuilder(1000, 0.01)
                .hashFunction((value, m, k) -> null)
                .buildBloomFilter();
    }
View Full Code Here

                .buildBloomFilter();
    }

    public static void testPerformance() throws UnknownHostException, IOException {
        //Test the performance of the in-memory Bloom filter
        BloomFilter<String> bf = new FilterBuilder(100_000, 0.01).hashFunction(HashMethod.Murmur3).buildBloomFilter();
        MemoryBFTest.benchmark(bf, "Normal Bloom Filter", 1_000_000);

        //And the Redis-backed BF
        String IP = "192.168.44.132";
        String filterName = "normalbloomfilter";
        //Open a Redis-backed Bloom filter
        CountingBloomFilter<String> cbfr = new FilterBuilder(10000, 0.01).redisBacked(true).buildCountingBloomFilter();
        MemoryBFTest.benchmark(cbfr, "Redis Test", 10_000);
        cbfr.remove();


        List<BloomFilter<String>> bfs = new ArrayList<>();
        CountingBloomFilter<String> first = new FilterBuilder(1000, 0.01)
                .redisBacked(true)
                .buildCountingBloomFilter();
        bfs.add(first);
        for (int i = 1; i < 10; i++) {
            bfs.add(first.clone());
View Full Code Here

        return millis * 1_000_000;
    }

    @Test
    public void addAndLetExpire() throws Exception {
        FilterBuilder b = new FilterBuilder(1000, 0.05);
        ExpiringBloomFilter<String> filter = new ExpiringBloomFilter<String>(b);
        filter.reportRead("1", fromMillis(100));
        assertTrue(filter.isCached("1"));
        assertFalse(filter.contains("1"));
        filter.reportWrite("1");
View Full Code Here

        assertFalse(filter.contains("1"));
    }

    @Test
    public void exceedCapacity() {
        FilterBuilder b = new FilterBuilder(100, 0.05);
        ExpiringBloomFilter<String> filter = new ExpiringBloomFilter<>(b);

        IntStream.range(0, 200).forEach(i -> {
            filter.reportRead(String.valueOf(i), fromMillis(1000));
            filter.reportWrite(String.valueOf(i));
View Full Code Here


    @Test
    public void testSlaveReads() throws Exception{
        int m = 1000, k = 10;
        FilterBuilder fb = new FilterBuilder(m,k)
                .name("slavetest")
                .redisBacked(true)
                .addReadSlave(Helper.host, Helper.port);
                //.addReadSlave(Helper.host, Helper.port +1);

        BloomFilter<String> filter = counts ? fb.buildCountingBloomFilter() : fb.buildBloomFilter();

        List<String> items = IntStream.range(0, 100).mapToObj(i -> "obj" + String.valueOf(i)).collect(Collectors.toList());
        items.forEach(filter::add);

        //On localhost, there is no perceivable replication lag
View Full Code Here

        first.add(testString);
        System.out.println(first.asString());

        BloomFilter<String> loaded;
        if(counts)
            loaded = new FilterBuilder(n, p).name(name).redisBacked(true).buildCountingBloomFilter();
        else
            loaded = new FilterBuilder(n, p).name(name).redisBacked(true).buildBloomFilter();

        System.out.println(loaded.asString());
        assertTrue(loaded.contains(testString));

        loaded.add(testString2);
View Full Code Here

        // final CBloomFilter<String> cbfr = new CBloomFilter<String>(10000, 10, 4);
        Thread[] ts = new Thread[threads];
        for (int i = 0; i < threads; i++) {
            final int id = i;
            Runnable run = () -> {
                CountingBloomFilter<String> filter = new FilterBuilder(m, k).name(name).redisBacked(true).buildCountingBloomFilter();
                for (int j = 0; j < objects; j++) {
                    String str = real.get((int) (Math.random() * objects));
                    String before = filter.getBitSet().toString();
                    filter.add(str);
                    String between = filter.getBitSet().toString();
View Full Code Here

    public static RedisPool getPool() {
        return new RedisPool(host, port, connections, null);
    }

    public static <T> BloomFilterMemory<T> createFilter(int m, int k, HashMethod hm) {
        return new BloomFilterMemory<>(new FilterBuilder(m, k).hashFunction(hm).complete());
    }
View Full Code Here

    public static <T> BloomFilterMemory<T> createFilter(int m, int k, HashMethod hm) {
        return new BloomFilterMemory<>(new FilterBuilder(m, k).hashFunction(hm).complete());
    }

    public static <T> BloomFilterMemory<T> createFilter(int n, double p, HashMethod hm) {
        return new BloomFilterMemory<>(new FilterBuilder(n, p).hashFunction(hm).complete());
    }
View Full Code Here

TOP

Related Classes of orestes.bloomfilter.FilterBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.