diff options
| author | levlam <levlam@telegram.org> | 2025-06-23 01:54:42 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2025-06-23 01:54:42 +0300 |
| commit | 6614c148781db9cdc492c7c428ce685fa3f49abe (patch) | |
| tree | d2ffa658d7ff3751707ea39c53bc367dc057eefe /tdutils/td | |
| parent | 3c8bbc53c34bd0ef8ffdc406c9c8d8b71db73465 (diff) | |
Add WaitFreeHashSet::remove_if.
Diffstat (limited to 'tdutils/td')
| -rw-r--r-- | tdutils/td/utils/WaitFreeHashSet.h | 15 | ||||
| -rw-r--r-- | tdutils/td/utils/algorithm.h | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tdutils/td/utils/WaitFreeHashSet.h b/tdutils/td/utils/WaitFreeHashSet.h index 68d1baabc..f5a51b095 100644 --- a/tdutils/td/utils/WaitFreeHashSet.h +++ b/tdutils/td/utils/WaitFreeHashSet.h @@ -97,6 +97,21 @@ class WaitFreeHashSet { } } + template <class F> + bool remove_if(const F &f) { + if (wait_free_storage_ == nullptr) { + return default_set_.remove_if(f); + } + + bool is_removed = false; + for (auto &it : wait_free_storage_->sets_) { + if (it.remove_if(f)) { + is_removed = true; + } + } + return is_removed; + } + KeyT get_random() const { if (wait_free_storage_ != nullptr) { for (size_t i = 0; i < MAX_STORAGE_COUNT; i++) { diff --git a/tdutils/td/utils/algorithm.h b/tdutils/td/utils/algorithm.h index 6107b1d29..d225a46a9 100644 --- a/tdutils/td/utils/algorithm.h +++ b/tdutils/td/utils/algorithm.h @@ -309,4 +309,12 @@ bool table_remove_if(WaitFreeHashMap<KeyT, ValueT, HashT, EqT> &table, const Fun return table.remove_if(func); } +template <class KeyT, class HashT, class EqT> +class WaitFreeHashSet; + +template <class KeyT, class HashT, class EqT, class FuncT> +bool table_remove_if(WaitFreeHashSet<KeyT, HashT, EqT> &table, const FuncT &func) { + return table.remove_if(func); +} + } // namespace td |
