English 中文(简体)
需要一个地图,以便通过钥匙更快地进行检索,并找到一些范围带有钥匙的条目清单
原标题:Need a Map for faster retrievals by key & for getting a list of entries with keys in some range

I need a Map<Integer,String> with a major need to do fast retrievals of values by key. However I also have the need to retrieve List of all entries (key, value pairs) whose keys are in range (n1 to n2). However, No sorting required in the list. The map would hold atleast 10,000 such entries.

I initially thought of using TreeMap but that doesn t help with faster retrievals(O(log n) for get() operations). Is it possible to get a list of entries from HashMap whose keys are in range n1 to n2 ?

What would be my best bet to go with ?

最佳回答

The two implementation of NavigableMap (允许你根据关键幅度检索分图或分图)为<代码>TreeMap和Con CurrentSkipListMap,两者均提供O(log n)接入时间。

假设你要求O(1)按照常规的“条形表>HashMap>/条形,我建议采用你自己的(效率低的)“关键范围”方法。 也就是说,为改进准入时间而牺牲了关键远程操作的表现,你用一个固定的“HashMap>>/编号。 这里确实有另一种方式: <条形> 地图>/编号方法必然取决于以某种方式储存的数据,这意味着你永远无法达到O(1)的存取时间。

问题回答

如何分配钥匙? 对于10 000名人员,如0至19999等20 000多个可能性,我可以想象,对4至14名人员进行搜查会受到罚款。 你们会错失50%。

我想知道,为什么树苗不能够帮助更快地回收(O(log n)用于()操作?

如果你们的树有较小的价值观和较大的树木,你就可以返回大片的树木。 需要地图和清单?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签