Skip to content

hash 以string 为key的时候的计算方式 #146

Description

@zanewong233
template <> struct hash<string> {
    std::size_t operator()(string const &val) const noexcept {
        return std::hash<char const *>{}(val.c_str());
    }
};

这里边自定义的hash对于string为key时用的是字符串的地址值作为散列函数的输入,正常来说不是应该按照string的内容来散列的吗?这么设计是有什么考虑吗?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions