// TODO: does not detect set type (hash/tree) when it's synchronized
static Set cloneSet(Set set) {
synchronized(collectionMutex(set)) {
if (set instanceof TreeSet) ret new TreeSet(set);
if (set instanceof LinkedHashSet) ret new LinkedHashSet(set);
ret new HashSet(set);
}
}