diff options
author | sudaques <[email protected]> | 2025-03-10 16:11:55 +0300 |
---|---|---|
committer | sudaques <[email protected]> | 2025-03-10 16:42:23 +0300 |
commit | 40b5a1b2172e3284a705eeb05b3ee465257c815b (patch) | |
tree | 0651a48ac8f432320b12550d206dc9e0e149edb1 | |
parent | 150da77343479ec4bf75bf413f06a3c1763dfd4c (diff) |
TConcurrentHashMap::TryRemove
commit_hash:f9faa4cdcf43ef641c640ec86712f48b09031dcb
-rw-r--r-- | library/cpp/containers/concurrent_hash/concurrent_hash.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/library/cpp/containers/concurrent_hash/concurrent_hash.h b/library/cpp/containers/concurrent_hash/concurrent_hash.h index 74573ecc095..6fed13ee8d5 100644 --- a/library/cpp/containers/concurrent_hash/concurrent_hash.h +++ b/library/cpp/containers/concurrent_hash/concurrent_hash.h @@ -58,6 +58,16 @@ public: return r; } + bool TryRemoveUnsafe(const K& key, V& result) { + typename TActualMap::iterator it = Map.find(key); + if (it == Map.end()) { + return false; + } + result = std::move(it->second); + Map.erase(it); + return true; + } + bool HasUnsafe(const K& key) const { typename TActualMap::const_iterator it = Map.find(key); return (it != Map.end()); @@ -154,6 +164,12 @@ public: return bucket.RemoveUnsafe(key); } + bool TryRemove(const K& key, V& result) { + TBucket& bucket = GetBucketForKey(key); + TBucketGuard guard(bucket.Mutex); + return bucket.TryRemoveUnsafe(key, result); + } + bool Has(const K& key) const { const TBucket& bucket = GetBucketForKey(key); TBucketGuard guard(bucket.Mutex); |