1 package edu.berkeley.sbp.util;
4 // FEATURE: make this faster (plenty of ways: quadradic probing hash table is one)
5 /** a sparse mapping from pairs of <tt>int</tt>'s to <tt>V</tt>'s */
6 public final class IntPairMap<V> implements Iterable<V> {
8 private final HashMap<Long, V> hm = new HashMap<Long, V>();
10 private static long key(IntegerMappable k1, IntegerMappable k2) {
11 return (k1==null ? 0 : (((long)k1.toInt()) << 32)) | (k2==null ? 0 : k2.toInt());
14 public void put(IntegerMappable k1, IntegerMappable k2, V v) { hm.put(key(k1, k2), v); }
15 public V get(IntegerMappable k1, IntegerMappable k2) { return hm.get(key(k1, k2)); }
16 public Iterable<V> values() { return hm.values(); }
17 public int size() { return hm.size(); }
18 public void toArray(V[] v) { hm.values().toArray(v); }
19 public Iterator<V> iterator() { return hm.values().iterator(); }