I need to map a pair of long long
to a double
, but I'm not sure what hash function to use. Each pair may consist of any two numbers, although in practice they will usually be numbers between 0
and about 100
(but again, that's not guaranteed).
Here is the tr1::unordered_map
documentation. I started like this:
typedef long long Int;
typedef std::pair<Int, Int> IntPair;
struct IntPairHash {
size_t operator(const IntPair& p) const {
return ...; // how to hash the pair?
}
};
struct IntPairEqual {
bool operator(const IntPair& a, const IntPair& b) const {
return a.first == b.first
&& a.second == b.second;
}
};
tr1::unordered_map<IntPair, double, IntPairHash, IntPairEqual> myMap;
In general, I'm never sure what hash function to use. What's a good general-purpose hash function?