#include <string.h>

typedef unsigned long u_long;

u_long hash_string(const char* s, int len)
{
	u_long h = 0;
	int i = 0;
	if (len < 0)
		len = (s ? (int) strlen(s) : 0);
	while ( i++ < len)
	{
		h = 17 * h + * s++;
	}
	return h;
}

从别处转来的,找不到转载地址了。- -

经过测试,在大容量数组中定位,插入50000个字符串,冲突大部分能控制在2、3个左右,效果还是不错的。

相关文章:

  • 2022-12-23
  • 2021-09-01
猜你喜欢
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
相关资源
相似解决方案