のペアを にマップする必要がありますがlong long
、double
使用するハッシュ関数がわかりません。各ペアは、任意の 2 つの数字で構成されますが、実際には、通常はその前後の数字になります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;
一般に、どのハッシュ関数を使用すればよいかわかりません。優れた汎用ハッシュ関数とは?