使用TreeMap替代Properties。

huangapple go评论84阅读模式
英文:

Use TreeMap instead of Properties

问题

我有一个非常大的属性文件,其中包含国际化资源包(i18n resource bundle)。它的结构类似于:

button.browse=浏览
button.cancel=取消
button.clear=清除

请注意,键是可排序的,并且具有类似的前缀,我不希望出现重复项。
然后,这个属性文件通过java.util.Properties进行加载,并且仅通过get()进行查询,不会被更新。
由于Properties文件扩展了过时的Hashtable,我想使用其他的Map类来获得更好的性能。我可以使用更多的内存,但需要尽快地获取值。
默认情况下,我们总是使用HashMap,但据我了解,如果条目很多,它仍然会使用树状图作为节点。那么也许我可以直接使用TreeMap呢?
有没有适用于这种数据的更好的映射实现?例如,是否有使用键的前缀树的实现或类似的实现?

英文:

I have an extremely big properties file with i18n resource bundle. It looks like:

button.browse=Browse
button.cancel=Cancel
button.clear=Clear

Please note that keys are sortable and have similar prefixes and I don't expect to have duplicates.
The properties file then loaded via java.util.Properties and just queries with get() and never updated.
Since Properties file extends an obsolete Hastable I want to use other Map class for a better performance. I'm fine to use more memory but I need to get values as fast as possible.
By default we always using a HashMap but as far I understood if there is a lot of entries it anyway will use nodes as a tree map. So maybe I can just used the TreeMap instead?

Is any map implementation that is better for such kind of data? For example something that uses prefix tree from keys or something like that

答案1

得分: 0

HashMap仅在具有相同哈希码的条目的存储桶中使用树结构。对于这种本地化字符串,不应该有很多这样的条目。因此,在这里仍然更适合使用哈希映射。

英文:

HashMap uses tree only for a bucket with entries that have the same hashcode. It’s not expected to have a lot of them for such localized strings. So the hashmap is still better here

huangapple
  • 本文由 发表于 2020年9月9日 16:32:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63807771.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定