struct pairhash {
public:
template <typename T, typename U>
std::size_t operator()(const std::pair<T, U> &x) const
{
return std::hash<T>()(x.first) ^ std::hash<U>()(x.second);
}
};
class abc {
std::unordered_map<std::pair<int,int>, int, pairhash> rules;
};
struct c_hash {
inline size_t operator()(const tuple<int,int,int> & p) const {
return get<0>(p) * 100 + get<1>(p)*10 + get<2>(p);
}
};
int main(){
unordered_set<tuple<int,int,int>,c_hash>s;
s.insert(make_tuple(1,2,3));
return 0;
}
unordered_map/set自定义哈希函数
于 2022-04-30 17:17:42 首次发布