问题
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