invertKeysAndValuesKeepingNullKeys method
Return a map where the keys are the values, and the values are the keys.
Empty sets will become the key null
.
You can pass a new config
for the map.
Implementation
@useCopy
IMapOfSets<V?, K> invertKeysAndValuesKeepingNullKeys([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;
if (set.isEmpty) {
var destSet = result[null];
if (destSet == null) {
destSet = {};
result[null] = destSet;
}
destSet.add(key);
} else
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);
}