因为unordered_map内部是由哈希表实现的,哈希表中的每一项为一个桶,分别装着键和值,原stl中不包含pair<int,int>
类型的键,所以需要自定义
#include <iostream>
#include <unordered_map>
// 分别计算出内置类型的 Hash Value 然后对它们进行 Combine 得到一个哈希值
// 一般直接采用移位加异或(XOR)得到哈希值
struct HashFunc
{
template<typename T, typename U>
size_t operator()(const std::pair<T, U>& p) const {
return std::hash<T>()