使用pair作为unordered_map的键值

struct pair_hash
{
    template<class T1, class T2>
    std::size_t operator() (const std::pair<T1, T2>& p) const
    {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        return h1 ^ h2;
    }
};

unordered_map<pair<int, bool>, int, pair_hash> Map;

今天为了写leetcode 的每日一题《391. 完美矩形》,想到需要使用hash存储矩形内部的点,需要使用到pair和unordered_map,就查询了一下,在此记录。

上一篇:使用Bare Tail实时查看mysql的log日志


下一篇:MySQL5.6数据库只有my-default如何更改编码(最详细用了MySQL数据库一年的经验总结)