Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LinkedList作为HashMap don';不包含修改后的正确数据_Java_List_Hashmap - Fatal编程技术网

Java LinkedList作为HashMap don';不包含修改后的正确数据

Java LinkedList作为HashMap don';不包含修改后的正确数据,java,list,hashmap,Java,List,Hashmap,在遍历十六进制地址行的文本文件时,我试图保存一个行号列表,其中每个十六进制地址对应于每个地址 我正在使用一个长链接列表的哈希映射来保存十六进制地址,其中链接列表是长链接出现的行号列表 找到了我用作测试的txt文件,其中的一个简短摘录是: 0041f7a0 R 13f5e2c0 R 05e78900 R 004758a0 R 31348900 W 004a30e0 R 0041f7a0 R 13f5e2c0 R 05e78900 R 004758a0 R 31348900瓦 004a30e0 R

在遍历十六进制地址行的文本文件时,我试图保存一个行号列表,其中每个十六进制地址对应于每个地址

我正在使用一个长链接列表的哈希映射来保存十六进制地址,其中链接列表是长链接出现的行号列表

找到了我用作测试的txt文件,其中的一个简短摘录是:

0041f7a0 R 13f5e2c0 R 05e78900 R 004758a0 R 31348900 W 004a30e0 R 0041f7a0 R 13f5e2c0 R 05e78900 R 004758a0 R 31348900瓦 004a30e0 R 我解析每一行,并将十六进制地址保存为Long,然后使用我的代码(下面提供)填充映射

HashMap pMap=newhashmap();
//此声明是程序中的全局变量
//这些变量都是局部变量
长地址=新长地址(0);
字符串换行符;
字符串[]tempStr;
int lineNum=0;
BufferedReader br=新的BufferedReader(新文件读取器(文件));
而((newLine=br.readLine())!=null){
tempStr=newLine.split(“”);
address=Long.parseLong(tempStr[0],16);
如果(!pMap.containsKey(地址)){
LinkedList tempList=新建LinkedList();
添加(lineNum);
pMap.put(地址,圣殿骑士);
}
否则{
pMap.get(地址).add(lineNum);
}
lineNum++;
}
我在这里查看HashMap:

        int evictIndex = -1; //(to tell which ones have been called)
        int farthestIndex = -1; //the value of the farthest away call's index
        long farthestAddress = -1; //the address that contains the farthest away call

        for(int i = 0; i < pTableSize; i++) {
            Long addr = pTable[i][0]; //get the address that I'll be searching for
            LinkedList<Integer> curr = pMap.get(addr);
            for(Integer l : curr) {
               if(l-accessCt > 0 && l > farthestIndex) {
                    farthestIndex = l.intValue();
                    farthestAddress = addr;
               }
            }
        }

        for(int i = 0; i < pTableSize; i ++){ 
            if(pTable[i][0] == farthestAddress)
                evictIndex = i;
        }
int-index=-1//(告诉哪些人打过电话)
int-index=-1//最远呼叫的索引值
长地址=-1//包含最远呼叫的地址
for(int i=0;i0&&l>index){
farthestIndex=l.intValue();
地址=地址;
}
}
}
对于(inti=0;i
在此代码之后,每个地址的LinkedList只包含1个Long:地址的第一个匹配项。
有人能帮我吗?

您声明
LinkedList tempList=new LinkedList(),但您希望它是一个长的列表。怎么样
LinkedList tempList=newLinkedList()

编辑:

您确定
pMap
的范围正确吗?如果每次调用该方法时都重新初始化它,那么它将被覆盖。如果将其范围向上移动一个级别(实例变量),它应该可以工作

编辑2:

如果我正确理解了您的代码(并且按照您的预期方式实现了代码),那么它就可以正常工作。我得到的结果类似于
844754720=[12421275]

有很多地址只有一个linenum,所以你可能会被愚弄,以为你只得到了第一行

仅在一行中出现的地址数为:14314

多行中的地址数为:23383


至少在您指定的文件中。所以你真的有很多地址只出现在一行。这就是问题所在吗?

您确定您正确阅读了地址吗?(当您在“循环”中使用
LinkedList
,但将映射值声明为
LinkedList
)时,您确定这是代码的准确表示吗)您确定这段代码可以编译吗?当映射的值类型为
List
时,可以添加
列表。显示循环代码并读取值。我复制了部分,手工编写了其他部分——意外地编写了整数而不是Long@user1988892您能否发布一个完整的示例,展示如何读取和解析文本文件以及如何填充地图?您发布的代码看起来不错。代码按预期工作。错误必须存在于其他地方,例如重新初始化pMap(在循环中声明)或其他疏忽。在调试器中跟踪代码。@user1988892请参阅更新,并发布有关如何填充映射的代码。pMap是我程序中的一个全局变量,我只是在顶部添加了它以显示它声明的内容。@user1988892然后请给我们更多代码来处理。+1我也开始怀疑edit#2中的情况。
        int evictIndex = -1; //(to tell which ones have been called)
        int farthestIndex = -1; //the value of the farthest away call's index
        long farthestAddress = -1; //the address that contains the farthest away call

        for(int i = 0; i < pTableSize; i++) {
            Long addr = pTable[i][0]; //get the address that I'll be searching for
            LinkedList<Integer> curr = pMap.get(addr);
            for(Integer l : curr) {
               if(l-accessCt > 0 && l > farthestIndex) {
                    farthestIndex = l.intValue();
                    farthestAddress = addr;
               }
            }
        }

        for(int i = 0; i < pTableSize; i ++){ 
            if(pTable[i][0] == farthestAddress)
                evictIndex = i;
        }