// A: object type
// B: hash type (e.g. Long)
sclass UniquifyUsingHasher {
settable IF1 hasher;
*(IF1 *hasher) {}
new MultiMap byHash;
gettable new L list;
bool add(A a) {
B hash = hasher.get(a);
if (byHash.containsPair(hash, a)) false;
byHash.put(hash, a);
true;
}
selfType addAll(Iterable l) {
fOr (A a : l)
add(a);
this;
}
L get() { ret list; }
int nHashCollisions() { ret n(keysWithMultipleValues(byHash)); }
}