retainAll method
override
Removes all elements of this set that are not elements in elements
.
Checks for each element of elements
whether there is an element in this
set that is equal to it (according to this.contains
), and if so, the
equal element in this set is retained, and elements that are not equal
to any element in elements
are removed.
Implementation
void retainAll(Iterable<Object> elements) {
var valuesToRetain = new Set<V>.identity();
for (var element in elements) {
if (element != null && element is! V) continue;
var key = _keyForValue(element as V);
if (!_baseMap.containsKey(key)) continue;
valuesToRetain.add(_baseMap[key]);
}
var keysToRemove = [];
_baseMap.forEach((k, v) {
if (!valuesToRetain.contains(v)) keysToRemove.add(k);
});
keysToRemove.forEach(_baseMap.remove);
}