Question

For a simple C++ struct that has three ints to identify a unique structure, what can be a good hash function implementation if not too much is known about the realistic values of a,b and c. I need to use the struct as Key to unordered_map?

struct Key {

        int a, b, c;

    }
Was it helpful?

Solution

Pass the entire struct to Murmurhash: https://sites.google.com/site/murmurhash/

Don't try to mix the values yourself (e.g. the advice above to multiply, add, xor, etc). The whole point of leveraging a hash function is that it can already mix them very effectively. If you pre-mix, you're just taking away useful entropy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top