martinus / robin-hood-hashing

Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20
https://gitter.im/martinus/robin-hood-hashing
MIT License
1.52k stars 146 forks source link

Fix calcNumBytesInfo #46

Closed jamesob closed 5 years ago

jamesob commented 5 years ago

While testing I found that memory reported by calcNumBytesTotal() seemed suspiciously low. This seems like an obvious bug but maybe I'm missing something.

martinus commented 5 years ago

Also, calcNumBytesTotal calculates the number of bytes I need to allocate at once. This includes the info byte and space for either the elements directly (unordered_flat_map), or just a pointer (unordered_node_map) and the actual data will be allocated in a separate bulk allocator

jamesob commented 5 years ago

Ah, I see! My apologies. How would I express the bytes used by an unordered_node_map (excluding the value data behind the node pointers)?

Maybe something like map.calcNumBytesTotal(m.mask() + 1)?

martinus commented 5 years ago

No problem, I guess the name of the methods are a bit confusing. Yes, it should be map.calcNumBytesTotal(m.mask() + 1). Also be aware that whenever the map gets full, it doubles the size to 2 * (m.mask() + 1). After the map has rehashed all it's data into the newly allocated chunk, unordered_node_map does not just free the old chunk but put into the bulk allocator so it can be repurposed for object allocations