invertKeysAndValues method
Return a map where the keys are the values, and the values are the keys.
Keys of empty sets will be removed.
You can pass a new config
for the map.
Implementation
@useCopy
IMapOfSets<V, K> invertKeysAndValues([ConfigMapOfSets? config]) {
Map<V, Set<K>> result = {};
for (MapEntry<K, ISet<V>> entry in _mapOfSets.entries) {
K key = entry.key;
ISet<V> set = entry.value;
for (V value in set) {
var destSet = result[value];
if (destSet == null) {
destSet = {};
result[value] = destSet;
}
destSet.add(key);
}
}
return IMapOfSets<V, K>.withConfig(result, config ?? this.config);
}