如何以内存有效的方式对值上的大型hashmap进行排序?

时间:2016-12-24 00:52:47

标签: java arraylist collections hashmap

我正在开发一个项目,最后得到一个大型的hashmap,现在我正在尝试按值排序。

ArrayList<Map.Entry<String, Integer>> entries = new ArrayList<Map.Entry<String, Integer>>(BloomFilter.map.entrySet());

但是当我这样做时,我得到一个OutOfMemoryError。

有没有办法阻止这种情况?

编辑:这是我的,如果它在bloomfilter函数中

    hash1 =  MurmurHash2.hash32(genom);
    hash2 =  genom.hashCode();
    inList = true;

    for (int i = 0; i < k-1 ; i++) {

        hashedGenom = ( hash1 + hash2 * i) % a.size();
        hashedGenom = CheckForNegative(hashedGenom);

        if(!(a.get(hashedGenom))){

            a.set(hashedGenom);
            inList = false;
        } 
    }

    return inList;

这是我在做静电过滤器的地方:

        if(CheckIfThere(s, k, fBitset)){

        //  System.out.println("var");
        val = map.get(s);

        if(val != null){
            map.put(s, map.get(s) + 1);
            //map.remove(s);
            //map.put(s, new Integer(val + 1));
        }else{


            map.put(s,1);

        }

我基本上是,获取字符串并将其发送到CheckIfThere,如果它变为true,我将它放到hashmap中。

1 个答案:

答案 0 :(得分:1)

有几种算法可以解决它

但我认为最简单的方法是使用数据库。

你可以将所有值都插入mysql / oracle / sql server / postgres ......然后

select xxxx from xxx order by xxx

如果您担心数据库庞大且难以部署,请尝试sqlite

相关问题