Skip to content

Commit 4981527

Browse files
committed
[frozen-multi-map] Add the ability to determine if all values of all keys have been deleted from the mult-map.
This is useful to validate that a multi-map has been completely consumed as one erases values from it.
1 parent 5bd2725 commit 4981527

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

include/swift/Basic/FrozenMultiMap.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,19 @@ class FrozenMultiMap {
246246
auto optRange = makeOptionalTransformRange(baseRange, ToNonErasedValues());
247247
return makeTransformRange(optRange, PairWithTypeErasedOptionalSecondElt());
248248
}
249+
250+
/// Returns true if all values for all keys have been deleted.
251+
///
252+
/// This is intended to be used in use cases where a frozen multi map is
253+
/// filled up with a multi-map and then as we process keys, we delete values
254+
/// we have handled. In certain cases, one wishes to validate after processing
255+
/// that all values for all keys were properly handled. One cannot perform
256+
/// this operation with getRange() in a nice way.
257+
bool allValuesHaveBeenDeleted() const {
258+
return llvm::all_of(storage, [](const std::pair<Key, Optional<Value>> &pair) {
259+
return !pair.second.hasValue();
260+
});
261+
}
249262
};
250263

251264
template <typename Key, typename Value, typename Storage>

0 commit comments

Comments
 (0)