我需要将一对映射long long
到 a double
,但我不确定要使用什么哈希函数。每对可能由任意两个数字组成,尽管在实践中它们通常是介于0
和之间的数字100
(但同样,这并不能保证)。
这是tr1::unordered_map
文档。我是这样开始的:
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;
一般来说,我永远不确定要使用什么散列函数。什么是好的通用哈希函数?