c++ - 使用 hash_map 时,在 STL 字符串上使用的最佳散列算法是什么?

标签 c++ windows performance stl hash

我发现 VS2005 上的标准散列函数在尝试实现高性能查找时非常缓慢。有哪些快速高效的散列算法可以避免大多数冲突的好例子?

最佳答案

我曾与 Paul Larson 合作过微软研究院的一些哈希表实现。他在各种数据集上研究了许多字符串散列函数,发现简单的乘以 101 和加法循环的效果出奇的好。

unsigned int
hash(
    const char* s,
    unsigned int seed = 0)
{
    unsigned int hash = seed;
    while (*s)
    {
        hash = hash * 101  +  *s++;
    }
    return hash;
}

关于c++ - 使用 hash_map 时,在 STL 字符串上使用的最佳散列算法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/98153/

相关文章:

c++ - 如何在特定时间后从 `std::cin` 超时读取

c++ - 如何从链表中删除节点?

windows - 在 Windows 上运行的进程的完整路径

performance - 为什么这个 PowerShell 代码 (Invoke-WebRequest/getElementsByTagName) 在我的机器上如此缓慢,但在其他机器上却没有?

java - 对已编译的 jar 进行简单的性能修改?

c++ - 查找表示 GPS 路线的两条线之间的距离(MATLAB、Java、C++ 或 Python)

c# - C++ Interop : How do I call a C# class from native C++, 类是非静态的吗?

java - (PySpark) 路径错误 : exception in thread "main" java. io.ioexception 无法运行程序 "python"

python - 如何从 pip 搜索包的索引中删除 URL?

c - c 中的快速 I/O,stdin/out