sclass LineComp_PairIndex { delegate Node to LineComp_LinkedList_v2. MultiSetMap nodes = multiSetMap_innerHashSet_outerHashMap(); MultiSetMap byCount = multiSetMap_innerTreeSet_outerRevTreeMap(); IntPair nodeToPair(Node n) { ret n?.pair(); } // add node to pair index void add(Node n) { IntPair p = nodeToPair(n); if (p == null) ret; int count = nodes.getSize(p); nodes.add(p, n); byCount.remove(count, p); byCount.put(count+1, p); } // remove node from pair index void remove(Node n) { IntPair p = nodeToPair(n); if (p == null) ret; int count = nodes.getSize(p); if (count == 0) fail("Can't remove pair " + p); nodes.remove(p, n); byCount.remove(count, p); if (count-- > 0) byCount.put(count, p); } IntPair mostPopularDuplicate() { ret toInt(firstKey(byCount)) < 2 ? null : firstValue(byCount); } int numberOfDuplicates() { ret byCount.size()-l(byCount.get(1)); } int getCount(IntPair p) { ret nodes.getSize(p); } }