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

时间:2016-04-01 10:30:02

标签: c++ spell-checking

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

任何人都知道这种方法可以为一组字符生成一个唯一的数字吗?

1 个答案:

答案 0 :(得分:1)

实际上,标准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。

&#34;的std ::散列{}(STR)&#34;计算哈希值;