diff options
author | mikari <mikari@yandex-team.com> | 2025-01-13 22:57:50 +0300 |
---|---|---|
committer | mikari <mikari@yandex-team.com> | 2025-01-13 23:20:25 +0300 |
commit | 22cb6b0af9d074439b7a042dcefe2eeec11e954c (patch) | |
tree | 5b4c38c7601a72334465394b43ccf86048be4f66 | |
parent | f35fe00dcc2af8b9605460b0eba29304694c7d22 (diff) | |
download | ydb-22cb6b0af9d074439b7a042dcefe2eeec11e954c.tar.gz |
Implemented DropMissingKeys with return void
commit_hash:653cf2ccf4c62b37969f56b06881a120bb1ae5f6
-rw-r--r-- | yt/yt/core/misc/collection_helpers-inl.h | 14 | ||||
-rw-r--r-- | yt/yt/core/misc/collection_helpers.h | 5 |
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 |