Max Max - 8 months ago 84
C++ Question

Does std::unordered_map<int,float> still have to hash the integer to get to the value?

I would like to know whether

std::unordered_map< int, float >
still has to hash the given integer to get to the value or just uses it straight away. I need to perform this operation very fast many times a second and as
std::hash<int>
isn't guaranteed to be the identity function, how would I go about redefining it? (obviously not using STL and writing my own containers is possible, but I doubt those written by me will be more efficient (likely much, much slower)).
Thanks!

Answer Source

I would like to know whether std::unordered_map< int, float > still has to hash the given integer

Yes it does.

I need to perform this operation very fast many times

Did you complete your project and witnessed that this is the bottleneck of it? If not, then watch out, since you might end up as a victim of premature optimization!

how would I go about redefining it?

You have to write your own code then. Example: C++ unordered_map using a custom class type as the key, where you would use struct Key { int value; };.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download