Java Hash Multi Map(具有多个值的键)实现 [英] Java Hash Multi Map (key with multiple values) Implementation

查看:1525
本文介绍了Java Hash Multi Map(具有多个值的键)实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处 ,我发现Colt的 OpenIntIntHashMap 和Trove的 TIntIntHashMap 比Java内置的 HashMap 或Guava的 HashMultimap



做Colt的 OpenIntIntHashMap 或Trove的 TIntIntHashMap 允许具有多个值的键,如 HashMultimap ?如果不是实现可以实现Colt或Trove的性能和内存效率的 HashMultimap 的好方法?



注意:我已经测试过Guava的 HashMultimap ,但是它的性能和内存效率对我来说似乎很差。 解决方案

  Multimaps.newSetMultimap(
TDecorators.wrap(new TIntObjectHashMap< Collection< Integer>>()),
new Supplier< Set<整数>>(){
public Set< Integer> get(){
return TDecorators.wrap(new TIntHashSet());
}
});


From here, I found that Colt's OpenIntIntHashMap and Trove's TIntIntHashMap give better performance and memory uses than Java's built in HashMap or Guava's HashMultimap.

Do Colt's OpenIntIntHashMap or Trove's TIntIntHashMap allow keys with multiple values, as with HashMultimap? If not what is a nice way to implement a HashMultimap that can achieve Colt's or Trove's performance and memory efficiency?

Note: I have tested Guava's HashMultimap, but its performance and memory efficiency seems poor to me.

解决方案

Multimaps.newSetMultimap(
  TDecorators.wrap(new TIntObjectHashMap<Collection<Integer>>()),
  new Supplier<Set<Integer>>() {
    public Set<Integer> get() {
      return TDecorators.wrap(new TIntHashSet());
    }
  });

这篇关于Java Hash Multi Map(具有多个值的键)实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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