How to use unordered_set that has elements that are vector of pair

前端 未结 2 1292
别那么骄傲
别那么骄傲 2020-12-13 21:05

I wanted to have something like

 unordered_set>> us;

but even without pair:

#includ         


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 21:45

    You should write a hasher for your types, for example:

    class MyHash
    {
    public:
        std::size_t operator()(const vector> &v) const
        {
            std::size_t x = 0;
    
            for (auto &i : v)
                x ^= std::hash()(i.first) ^ std::hash()(i.second);
    
            return x;
        }
    };
    
    
    int main()
    {
        unordered_set>, MyHash> um;
    }
    

    Note: The hash function that I wrote is just an example, it can be replaced with another and better one.

提交回复
热议问题