Times in progress, the development of society, the emergence of 64-bit machine is no longer easy to overflow, this is certainly a happy thing, can be in the system migration, suddenly found that 64-bit machine hash function results with 32 is not the same, shocked to quickly study the algorithm in the discovery is the problem of shift operation symbol.
No way, had to judge the system, and for 64-bit machine rewrite the algorithm, the code is as follows:
if (EXEC ("getconf long_bit") = = "+") {function _hash ($apszData = "", $MAX _table_num = 0) { $_hash = $x = $i = 0;
for ($i = 0; $i < strlen ($apszData); $i + +) { $_hash = ($_hash << 4) + ord ($apszData [$i]); if ($x = $_hash &0xf0000000)! = 0) { $_hash ^= ($x >>); $_hash &= ~ $x; } } Return ($_hash &0x7fffffff)% $MAX _table_num + 1; }} else {function _hash ($apszData = "", $MAX _table_num = 0) { $hash = $x = $i = 0; for ($i = 0; $i < strlen ($apszData); $i + +) { $hash = ($hash << 4) + ((Ord ($apszData [$i])) << +); if ($x = $hash &0xf000000000000000)! = 0) { $hash ^= $x >>; $hash &= (~ $x) &0xFFFFFFFF00000000; } } $ret = ($hash &0x7fffffff00000000)% ($MAX _table_num << +) + (1 << +); $ret >>=; $ret &= 0xFFFFFFFF; return $ret; }}
http://www.bkjia.com/PHPjc/735127.html www.bkjia.com true http://www.bkjia.com/PHPjc/735127.html techarticle times in progress, the development of society, the emergence of 64-bit machine is no longer easy to overflow, this is a happy thing, can be in the system migration, suddenly found 64-bit machine ...