sclass Splitter2 { HashMap> map = new HashMap; // may return null if unknown B get(A a) { MultiSet ms = map.get(a); ret ms == null ? null : ms.getMostPopularEntry(); } void learn(A a, B b) { MultiSet ms = map.get(a); if (ms == null) map.put(a, ms = new MultiSet); ms.add(internIfString(b)); } void unlearn(A a, B b) { MultiSet ms = map.get(a); if (ms == null) ret; ms.remove(b); if (empty(ms)) map.remove(a); } void clear { map.clear(); } }