boost::unordered_map missing reserve() like std::unordered_map

China☆狼群 提交于 2020-01-21 18:34:44

问题


For my next task I need to use a very big hash; since I have an old compiler I cannot use C++0x std::unordered_map. Ideally I need is a call to reserve to make room in advance for a large number of items. I cannot find this method in boost::unordered_map: is there any place or function that achieves the same?

The 2 associative container are the same; I can see rehash function and the same constructor for controlling the number of buckets, but not a function about a number of elements.

Can you help me with that?


回答1:


reserve can be emulated by rehash as in Table 103 in N3376.

a.rehash(n) 
Post: a.bucket_count() > a.size() / a.max_load_factor() 
      and a.bucket_count() >= n.

a.reserve(n) Same as a.rehash(ceil(n / a.max_load_factor()))


来源:https://stackoverflow.com/questions/10617829/boostunordered-map-missing-reserve-like-stdunordered-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!