What#39;s the best hashing algorithm to use on a stl string when using hash_map?(使用 hash_map 时,在 stl 字符串上使用的最佳散列算法是什么?)
问题描述
我发现 VS2005 上的标准散列函数在尝试实现高性能查找时非常缓慢.有哪些快速有效的散列算法可以避免大多数冲突的好例子?
I've found the standard hashing function on VS2005 is painfully slow when trying to achieve high performance look ups. What are some good examples of fast and efficient hashing algorithms that should void most collisions?
推荐答案
我与 Paul Larson 一起工作 Microsoft Research 的一些哈希表实现.他在各种数据集上研究了许多字符串散列函数,发现简单的乘以 101 和加法循环的效果出奇地好.
I worked with Paul Larson of Microsoft Research on some hashtable implementations. He investigated a number of string hashing functions on a variety of datasets and found that a simple multiply by 101 and add loop worked surprisingly well.
unsigned int
hash(
const char* s,
unsigned int seed = 0)
{
unsigned int hash = seed;
while (*s)
{
hash = hash * 101 + *s++;
}
return hash;
}
这篇关于使用 hash_map 时,在 stl 字符串上使用的最佳散列算法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 hash_map 时,在 stl 字符串上使用的最佳散列算法是什么?
基础教程推荐
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
