skarupke / flat_hash_map

A very fast hashtable
1.69k stars 186 forks source link

Fast clear when both the key and value type are trivially destructible #48

Closed waltimc closed 1 year ago

waltimc commented 1 year ago

I have a map with 16 million entries and calling clear() takes around 50 to 100 milliseconds.

The clear() function destroys every entry in a for loop. But if both the key and value types are 'is_trivially_destructible', (for example map<int, int>) then it does not have to call the destructor on every key/value.

This reduces the time spent in clear() to less than 1 microsecond.