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 HashMapBag implements MapBag {
private final HashMap> hm = new HashMap>();
public void add(K k, V v) {
HashSet hs = hm.get(k);
if (hs==null) hm.put(k, hs = new HashSet());
hs.add(v);
}
public void addAll(K k, Iterable iv) {
for(V v : iv) add(k, v);
}
public HashSet getAll(K k) {
HashSet ret = hm.get(k);
if (ret==null) return new HashSet();
return ret;
}
public Iterator iterator() { return hm.keySet().iterator(); }
}