我想为 std::unordered_map 编写自己的 Hash_function 而不是使用默认函数。我可以在许多网站上找到 unordered_map::hash_function()。但是使用这个我只能得到生成的哈希值,使用这样的东西:
/*Sample map of strings*/
unordered_map<string, string> sample;
// inserts key and elements
sample.insert({ "Tom", "MNNIT" });
sample.insert({ "Kate", "MNNIT" });
unordered_map<string, string>::hasher foo
= sample.hash_function();
cout << foo("Tom") << endl;
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能有更多的控制权并创建我自己的散列函数版本?因此,例如,对于键“Tom”,我希望哈希值为 100。