two ways to customize unordered_set

         auto hash = [](const pair_type &p) {
                return std::hash<int>{}(p.first) ^ std::hash<int>{}(p.second);
            };

        auto equal = [](const pair_type &a, const pair_type &b) -> bool {
            return a.first == b.first && a.second == b.second || a.first == b.second && a.second == b.first;
        };

        unordered_set<pair_type, decltype(hash), decltype(equal)> connected_map(10, hash, equal);
struct MyHash
{
    std::size_t operator()(const pair_type &p) const // tj : note the const function qualifier is crucial
    {
        return std::hash<int>{}(p.first) ^ std::hash<int>{}(p.second);
    }
};


struct MyEqual
{
    bool operator()(const pair_type& a, const pair_type& b) const // tj : note the const function qualifier is crucial
    {
        return a.first == b.first && a.second == b.second || a.first == b.second && a.second == b.first;
    }
};


unordered_set<pair_type, MyHash, MyEqual> connected_map;

https://stackoverflow.com/questions/73872919/does-unordered-set-not-support-unordered-setvectorint-or-unordered-setpa

你可能感兴趣的:(哈希算法,算法)