I'm using the std::unordered_map
from gnu++0x to store a huge amount of data. I want to pre-allocate space for the large number of elements, since I can bound the total space used.
What I would like to be able to do is call:
std::unordered_map m;
m.resize(pow(2,x));
where x is known.
std::unordered_map
doesn't support this. I would rather use std::unordered_map
if possible, since it will eventually be part of the standard.
Some other constraints:
Need reliable O(1) access and mutation of the map. The desired hash and comparison functions are already non-standard and somewhat expensive. O(log n) mutation (as with std::map
) is too expensive.
-> The expensive hash and comparison also make amortization-based growth way too expensive. Each extra insert requires O(n) operations from those functions, which results in an extra quadratic term in the algorithm's run time, since the exponential storage requirements need O(n) growths.