相关疑难解决方法(0)

`std :: vector`的快速哈希函数

我实现了这个解决方案来获取哈希值vector<T>:

namespace std
{
    template<typename T>
    struct hash<vector<T>>
    {
        typedef vector<T> argument_type;
        typedef std::size_t result_type;
        result_type operator()(argument_type const& in) const
        {
            size_t size = in.size();
            size_t seed = 0;
            for (size_t i = 0; i < size; i++)
                //Combine the hash of the current vector with the hashes of the previous ones
                hash_combine(seed, in[i]);
            return seed;
        }
    };
}

//using boost::hash_combine
template <class T>
inline void hash_combine(std::size_t& seed, T const& v)
{
    seed ^= std::hash<T>()(v) + 0x9e3779b9 + …
Run Code Online (Sandbox Code Playgroud)

c++ hash vector c++11

6
推荐指数
2
解决办法
5424
查看次数

标签 统计

c++ ×1

c++11 ×1

hash ×1

vector ×1