xenium icon indicating copy to clipboard operation
xenium copied to clipboard

How do I clear all elements from a vyukov_hash_map<>?

Open charles-juicelabs opened this issue 2 years ago • 1 comments

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

charles-juicelabs avatar Aug 25 '23 08:08 charles-juicelabs

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);
}

mpoeter avatar Sep 03 '23 15:09 mpoeter