remove()方法太慢了 [英] remove() method is too slow

查看:198
本文介绍了remove()方法太慢了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一个记忆痕迹有问题。我已经阅读并在地图上保存了这些页面及其参考资料



地图结构:

 映射<整数,列表<整数>> map = new HashMap<>(); 

然后我再次读取该文件,并从整数列表中删除引用

  FileReader arq = new FileReader(new File(Path)); 
BufferedReader reader = new BufferedReader(arq,41943040);
while((std = reader.readLine())!= null){
requestedPage = Integer.parseInt(std,16);
//做某事
M.map.get(requestedPage).remove(0));
}

问题是删除那些引用和大的痕迹需要太长时间需要几个小时才能删除引用。有没有人有其他解决方案?



谢谢!

解决方案

认为如果 remove(0)是您在此列表中唯一的删除操作,一个LinkedList是一个更好的数据结构:



尝试:

 映射<整数,LinkedList<整数>> map = new HashMap< Integer,LinkedList< Integer>>(); 


i have a problem reading a memory trace. I've read it and saved the pages and their references on a map

Map structure:

    Map<Integer, List<Integer>> map = new HashMap<>();

And then i read the file again and remove the references from the Integer List

FileReader arq = new FileReader(new File(Path));
BufferedReader reader = new BufferedReader(arq, 41943040);
while ( (std = reader.readLine()) != null ) {
        requestedPage = Integer.parseInt(std, 16);
        //do something
        M.map.get(requestedPage).remove(0));
    }

The problem is it takes too long to remove those references and for big traces it takes hours to remove the references. Does anyone have another solution?

Thank you!

解决方案

I think that if remove(0) is the only remove operation you're going to make on this list a LinkedList is a much better data structure:

try:

Map<Integer, LinkedList<Integer>> map = new HashMap<Integer, LinkedList<Integer>>();

这篇关于remove()方法太慢了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆