ktprime / emhash

Fast and memory efficient c++ flat hash map/set
MIT License
435 stars 30 forks source link

shrink_to_fit error #16

Closed DoThingYo closed 1 year ago

DoThingYo commented 1 year ago

Dear author,

Thanks so much for your great library. But I just got an error for "../emhash/hash_table7.hpp:1326: void emhash7::HashMap<KeyT, ValueT, HashT, EqT>::rehash(uint64_t) [with KeyT = int; ValueT = float; HashT = std::hash; EqT = std::equal_to; uint64_t = long unsigned int]: Assertion `buckets < max_size() && buckets > _num_filled' failed." when "shrink_to_fit()" function was calling.

Could you please help me with this problem?

Best regards, Bob

ktprime commented 1 year ago

thanks for report issue, I have fixed it and try again. Most time you should not call function "shrink_to_fit()" only if you care about memory usage with many erasion and without insertion (rehashing is expensive).

不建议主动调用shrink_to_fit(), 除非使用场景对内存使用量敏感,而且是大量删除之后很少再插入(否则只做rehash不回收内存)