X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FIntPairMap.java;fp=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FIntPairMap.java;h=c355488ec01826f06eacd1409ff2837f03767492;hb=21b1b10a3ffb4b2021ad940f9cd722e3ed5300c4;hp=0000000000000000000000000000000000000000;hpb=64dc2f6c4d56dc4525f49c59119a4777540facf0;p=sbp.git diff --git a/src/edu/berkeley/sbp/util/IntPairMap.java b/src/edu/berkeley/sbp/util/IntPairMap.java new file mode 100644 index 0000000..c355488 --- /dev/null +++ b/src/edu/berkeley/sbp/util/IntPairMap.java @@ -0,0 +1,18 @@ +package edu.berkeley.sbp.util; +import java.util.*; + +/** a mapping from keys of type K to sets of values of type T */ +public final class IntPairMap { + + private final HashMap hm = new HashMap(); + + private static long key(IntegerMappable k1, IntegerMappable k2) { + return (k1==null ? 0 : (((long)k1.toInt()) << 32)) | (k2==null ? 0 : k2.toInt()); + } + + public void put(IntegerMappable k1, IntegerMappable k2, V v) { hm.put(key(k1, k2), v); } + public V get(IntegerMappable k1, IntegerMappable k2) { return hm.get(key(k1, k2)); } + public Iterable values() { return hm.values(); } + public int size() { return hm.size(); } + public void toArray(V[] v) { hm.values().toArray(v); } +}