【发布时间】:2010-10-18 19:01:23
【问题描述】:
我需要将一对long long 映射到double,但我不确定要使用什么哈希函数。每对可能由任意两个数字组成,尽管实际上它们通常是介于0 和大约100 之间的数字(但同样不能保证)。
Here 是 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;
一般来说,我永远不确定要使用什么哈希函数。什么是好的通用哈希函数?
【问题讨论】:
-
您是否考虑过使用以下一种或多种通用哈希函数:partow.net/programming/hashfunctions/index.html 它们非常快速且高效。
标签: c++ hash tr1 unordered-map hash-function