xenium
xenium copied to clipboard
How do I clear all elements from a vyukov_hash_map<>?
Hi,
Thank you for the xenium library. I've been using it, to good effect, to hash values from multiple threads with a reasonable amount of contention. Performance is great.
How should I be clearing all values from the vyukov_hash_map<>? I am currently recreating the object in-place by calling the destructor explicitly and then invoking placement new. But I think I must have missed something?
typedef xenium::vyukov_hash_map<..., ..., xenium::policy::reclaimer<xenium::reclamation::epoch_based<>>> VyukovHashMap;
hashMap.~VyukovHashMap();
new (&hashMap) VyukovHashMap;
Thanks, Charles
Hi Charles, happy to hear that! ATM there is not clear method. You can clear the map by iterating over the entries and calling erase for each one - that is essentially what the destructor is doing as well:
auto it = begin();
while (it != end()) {
erase(it);
}