<?php

function BKDRHash($str)
{
	$seed = 131; // 31 131 1313 13131 131313 etc..
	$hash = 0;
	
	$cnt = strlen($str);

	for($i = 0; $i < $cnt; $i++)
	{
		
		$hash = ((floatval($hash * $seed) & 0x7FFFFFFF) + ord($str[$i])) & 0x7FFFFFFF;
		
	}
	return ($hash & 0x7FFFFFFF);
}
echo BKDRHash('ggsonic');//1471979560
echo BKDRHash('asdfasdfasdf123'); // 1220655578

?>


http://www.cnblogs.com/uvsjoh/archive/2012/03/27/2420120.html
http://www.daimami.com/php/198692.htm

另外 10万以内的数据量可以用 CRC32 (https://yq.aliyun.com/articles/2469)代替
crc32 冲突率测试报告 http://www.backplane.com/matt/crc64.html
生日攻击:http://baike.baidu.com/view/1474504.htm
有50%冲突概率 试验次数n大约为: 1.17sqr(N) N为hash 表范围

相关文章:

  • 2021-09-25
  • 2021-10-09
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案