aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormikari <mikari@yandex-team.com>2025-01-13 22:57:50 +0300
committermikari <mikari@yandex-team.com>2025-01-13 23:20:25 +0300
commit22cb6b0af9d074439b7a042dcefe2eeec11e954c (patch)
tree5b4c38c7601a72334465394b43ccf86048be4f66
parentf35fe00dcc2af8b9605460b0eba29304694c7d22 (diff)
downloadydb-22cb6b0af9d074439b7a042dcefe2eeec11e954c.tar.gz
Implemented DropMissingKeys with return void
commit_hash:653cf2ccf4c62b37969f56b06881a120bb1ae5f6
-rw-r--r--yt/yt/core/misc/collection_helpers-inl.h14
-rw-r--r--yt/yt/core/misc/collection_helpers.h5
2 files changed, 17 insertions, 2 deletions
diff --git a/yt/yt/core/misc/collection_helpers-inl.h b/yt/yt/core/misc/collection_helpers-inl.h
index 0bfa6d4ec2..1afff7460e 100644
--- a/yt/yt/core/misc/collection_helpers-inl.h
+++ b/yt/yt/core/misc/collection_helpers-inl.h
@@ -140,7 +140,7 @@ void MergeFrom(TTarget* target, const TSource& source)
}
template <class TMap, class TKeySet>
-TKeySet DropMissingKeys(TMap&& map, const TKeySet& set)
+TKeySet DropAndReturnMissingKeys(TMap&& map, const TKeySet& set)
{
TKeySet dropped;
for (auto it = map.begin(); it != map.end(); ) {
@@ -154,6 +154,18 @@ TKeySet DropMissingKeys(TMap&& map, const TKeySet& set)
return dropped;
}
+template <class TMap, class TKeySet>
+void DropMissingKeys(TMap&& map, const TKeySet& set)
+{
+ for (auto it = map.begin(); it != map.end(); ) {
+ if (!set.contains(it->first)) {
+ map.erase(it++);
+ } else {
+ ++it;
+ }
+ }
+}
+
template <class TMap, class TKey>
auto GetIteratorOrCrash(TMap&& map, const TKey& key)
{
diff --git a/yt/yt/core/misc/collection_helpers.h b/yt/yt/core/misc/collection_helpers.h
index f5f316ee30..4695096e25 100644
--- a/yt/yt/core/misc/collection_helpers.h
+++ b/yt/yt/core/misc/collection_helpers.h
@@ -40,7 +40,10 @@ template <class TSource, class TTarget>
void MergeFrom(TTarget* target, const TSource& source);
template <class TMap, class TKeySet>
-TKeySet DropMissingKeys(TMap&& map, const TKeySet& set);
+[[nodiscard]] TKeySet DropAndReturnMissingKeys(TMap&& map, const TKeySet& set);
+
+template <class TMap, class TKeySet>
+void DropMissingKeys(TMap&& map, const TKeySet& set);
/*!
* This function is supposed to replace a frequent pattern