diff options
| author | levlam <levlam@telegram.org> | 2025-06-23 01:37:48 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2025-06-23 01:37:48 +0300 |
| commit | 3c8bbc53c34bd0ef8ffdc406c9c8d8b71db73465 (patch) | |
| tree | 0fe1c837a659716f46da7f192b14ef42e647c966 /tdutils/td | |
| parent | 571e9c7be11a56e091e51322718122c26a111cb7 (diff) | |
Add WaitFreeHashMap::remove_if.
Diffstat (limited to 'tdutils/td')
| -rw-r--r-- | tdutils/td/utils/WaitFreeHashMap.h | 15 | ||||
| -rw-r--r-- | tdutils/td/utils/algorithm.h | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tdutils/td/utils/WaitFreeHashMap.h b/tdutils/td/utils/WaitFreeHashMap.h index 592ac96d9..956a1a865 100644 --- a/tdutils/td/utils/WaitFreeHashMap.h +++ b/tdutils/td/utils/WaitFreeHashMap.h @@ -161,6 +161,21 @@ class WaitFreeHashMap { } } + template <class F> + bool remove_if(const F &f) { + if (wait_free_storage_ == nullptr) { + return default_map_.remove_if(f); + } + + bool is_removed = false; + for (auto &it : wait_free_storage_->maps_) { + if (it.remove_if(f)) { + is_removed = true; + } + } + return is_removed; + } + size_t calc_size() const { if (wait_free_storage_ == nullptr) { return default_map_.size(); diff --git a/tdutils/td/utils/algorithm.h b/tdutils/td/utils/algorithm.h index a87de8ecb..6107b1d29 100644 --- a/tdutils/td/utils/algorithm.h +++ b/tdutils/td/utils/algorithm.h @@ -301,4 +301,12 @@ bool table_remove_if(FlatHashTable<NodeT, HashT, EqT> &table, FuncT &&func) { return table.remove_if(func); } +template <class KeyT, class ValueT, class HashT, class EqT> +class WaitFreeHashMap; + +template <class KeyT, class ValueT, class HashT, class EqT, class FuncT> +bool table_remove_if(WaitFreeHashMap<KeyT, ValueT, HashT, EqT> &table, const FuncT &func) { + return table.remove_if(func); +} + } // namespace td |
