trove4j

Java Hash Multi Map (key with multiple values) Implementation

前提是你 提交于 2020-01-01 16:56:52
问题 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

Why not allow an external interface to provide hashCode/equals for a HashMap?

家住魔仙堡 提交于 2019-12-18 04:36:06
问题 With a TreeMap it's trivial to provide a custom Comparator , thus overriding the semantics provided by Comparable objects added to the map. HashMap s however cannot be controlled in this manner; the functions providing hash values and equality checks cannot be 'side-loaded'. I suspect it would be both easy and useful to design an interface and to retrofit this into HashMap (or a new class)? Something like this, except with better names: interface Hasharator<T> { int alternativeHashCode(T t);

TIntObjectHashMap - get Key for given value

大城市里の小女人 提交于 2019-12-12 04:49:10
问题 How to get the key from Trove TIntObjectHashMap for a value that exists and been found in the map ?? if(map.containsValue(source)) { for (Entry<Integer, String> entry : map.entrySet()) { // entrySet() is not recognized by Trove? and i can not find any corresponding method ?? if (entry.getValue().equals(source)) { entry.getKey(); } } } 回答1: I would do something like this: TIntObjectMap<String> map = new TIntObjectHashMap<>(); map.put( 1, "a" ); map.put( 2, "b" ); AtomicInteger found = new

What is the name of this locking technique?

旧时模样 提交于 2019-12-10 14:03:11
问题 I've got a gigantic Trove map and a method that I need to call very often from multiple threads. Most of the time this method shall return true . The threads are doing heavy number crunching and I noticed that there was some contention due to the following method (it's just an example, my actual code is bit different): synchronized boolean containsSpecial() { return troveMap.contains(key); } Note that it's an "append only" map: once a key is added, is stays in there forever (which is

Java Hash Multi Map (key with multiple values) Implementation

强颜欢笑 提交于 2019-12-04 12:26:00
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>>()),