拼写检查器,单词的唯一编号

Spell checker, unique number for word

在学校里,我的老师复习了使用数字哈希或表示单词的键的高性能拼写检查。因此,存储的不是单词,而是密钥。然后使用字典中使用的相同算法将要检查的单词转换为其唯一编号。但是我想不起来这个方法叫什么了,需要自己写一个类似的方法。

有人知道这种为一组字符生成唯一编号的方法吗?

实际上标准 c++ 库有一个 hash template structure 用于:

#include <iostream>
#include <functional>

int main() {
    std::string str = "Programmer";
    std::size_t str_hash = std::hash<std::string>{}(str);
    std::cout << str_hash ;
    return 0;
}

将输出 2561445211。

"std::hash{}(str)"计算哈希值;