【发布时间】:2018-03-12 14:09:10
【问题描述】:
我想计算具有相同哈希值的值的数量。 倒排索引元素 {{I1, I2},"book"}。
//我的代码
for (String s1 : uniquewordslist)
{
if (invertedindex.containsKey(s1))
{
List<String> l1 = new ArrayList<>();
l1 = invertedindex.get(s1);
if (!l1.contains(key)) {
l1.add(key);
}
invertedindex.put(s1, l1);
}
else {
List<String> l2 = new ArrayList<String>();
l2.add(key);
invertedindex.put(s1, l2);
}
int count = Collections.frequency( ?????, invertedindex.values()); //
System.out.println(count);
它总是打印 0。应该是什么???地点
【问题讨论】:
-
您正在评估的哈希值在哪里,为什么
invertedindex.get(i).size()无法为您获取字符串键的列表值的大小? -
myString==book 请考虑一下
-
我没有得到 count_ 值。它应该打印 1。但它打印 0。
-
为什么要打印1?请澄清,你想计算什么?您有一个倒排索引,因此该元素看起来像
"book", ["string1", "string2", ..., "stringN"]。现在,你想数什么? -
invertedindex.values()返回一个包含所有列表的集合 - 这些列表未扁平化为单个列表。Collections.frequency计算此列表集合中出现的次数,但myString不是列表而是单个元素。因此,它将是 0
标签: java dictionary hash inverted-index