I want to implement a performance-optimized variant of unordered_map that works in several phases:
- Initialization: Insert about 100 elements into
std::map - Preparation: Do some magic, converting
std::mapto a variant ofstd::unordered_map - Work: Perform a large (unbounded) number of lookups; insertions/deletions are forbidden
In order to make the “work” phase as fast as possible, i would like to choose a hashing function that has no collisions for the given set of keys (gathered at initialization phase).
I would like to measure how much performance improvement i can get from this trick. So this is going to be an experiment, possibly going into production code.
Does the standard library have facilities for this implementation (e.g. finding how many collisions a given unordered_map has; or changing a hashing function)? Or should i make my own implementation instead?
Here is the “collision management” API:
In a nutshell,
bucket_size(n)gives you the number of collisions for the nth bucket. You can look up buckets with a key, and you can iterate over buckets with local_iterator.For changing a hash function, I would assign/construct a new container, from the old hash function to the new.