문제

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?

도움이 되었습니까?

해결책

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()))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top