小编shr*_*est的帖子

保存和重新加载番石榴Bloom过滤器时出错-需要帮助,以查找代码中的任何错误

我最近在生产中使用经典Bloom过滤器之前在Google上进行了测试。我正在使用番石榴库的版本18。当我运行以下程序时,由于sysout中的计数变化,我得到200多个。我看不到这里可能出什么问题,有人可以再看一眼吗?

import com.google.common.collect.Lists;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import com.google.common.hash.Hashing;
import org.apache.commons.lang3.RandomStringUtils;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.*;

/**
 * http://code.google.com/p/guava-libraries/wiki/HashingExplained
 * stackoverflow.com/questions/12319560/how-should-i-use-guavas-hashingconsistenthash
 */
public class GuavaHashing {
    private static final int N = 2500;

    public static void main(String[] args) throws IOException {
        List<String> ids = generateStoryIds(N);
        Set<String> testIds = generateTest(ids);
        bloomfiltertime(ids, testIds);
    }

    private static List<String> generateStoryIds(int size) {
        List<String> stories = new ArrayList<>();
        for (int i=0; i<size; ++i) {
            stories.add(RandomStringUtils.randomAlphanumeric(16));
        }
        return stories;
    }

    private …
Run Code Online (Sandbox Code Playgroud)

java bloom-filter guava

5
推荐指数
1
解决办法
833
查看次数

5
推荐指数
0
解决办法
1015
查看次数

将非空键和值放入哈希表时出现 NullPointerException

当 put() 的参数都不为 null 时,以下代码中会发生 java.util.Hashtable 的空指针异常:

import java.util.Hashtable;

interface action
{
   void method();
}

class forclass implements action
{
  public void method()
  {
    System.out.println("for(...){");
  }
}

class ifclass implements action
{
  public void method()
  {
    System.out.println("if(..){");
  }
}

public class trial
{
  static Hashtable<String,action> callfunc;
  //a hashtable variable
  public static void init()
  {
    //System.out.println("for"==null); //false
    //System.out.println(new forclass() == null); //false
    callfunc.put("for",new forclass()); //exception occuring here
    callfunc.put("if",new ifclass());
    //putting values into the hashtable
  }
  public static void main(String[] args)
  { …
Run Code Online (Sandbox Code Playgroud)

java hashtable nullpointerexception

3
推荐指数
1
解决办法
8686
查看次数

如何在 spring Cacheable 键的方法中指定多个参数

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html#cache-annotations-cacheable-key 上面的链接显示了当一个默认的缓存键不需要方法。但是如何在 Cacheable 注释中指定多个参数(但不是全部在方法 arg 列表中)作为缓存的键?

spring caching spring-cache

0
推荐指数
1
解决办法
3468
查看次数