Improve WaitFreeHashMap.
This commit is contained in:
parent
6f46b50b4b
commit
616455088f
@ -70,6 +70,11 @@ class WaitFreeHashMap {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
size_t count(const KeyT &key) const {
|
||||
const auto &storage = get_storage(key);
|
||||
return storage.count(key);
|
||||
}
|
||||
|
||||
// specialization for WaitFreeHashMap<..., unique_ptr<T>>
|
||||
template <typename ReturnT = decltype(ValueT().get())>
|
||||
ReturnT get_pointer(const KeyT &key) {
|
||||
@ -123,6 +128,21 @@ class WaitFreeHashMap {
|
||||
}
|
||||
}
|
||||
|
||||
void foreach(std::function<void(const KeyT &key, const ValueT &value)> callback) const {
|
||||
if (wait_free_storage_ == nullptr) {
|
||||
for (auto &it : default_map_) {
|
||||
callback(it.first, it.second);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MAX_STORAGE_COUNT; i++) {
|
||||
for (auto &it : wait_free_storage_->maps_[i]) {
|
||||
callback(it.first, it.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
if (wait_free_storage_ == nullptr) {
|
||||
return default_map_.size();
|
||||
|
Loading…
Reference in New Issue
Block a user