PHP sub-database and sub-table hash algorithm

WBOY
Release: 2016-07-29 08:41:07
Original
1956 people have browsed it

Copy the code The code is as follows:


//Sub-database and sub-table algorithm
function calc_hash_db($u, $s = 4)
{
$h = sprintf("%u", crc32($u) );
$h1 = intval(fmod($h, $s));
return $h1;
}
for($i=1;$i<100;$i++)
{
echo calc_hash_db($i) ;
echo "
";
}
function calc_hash_tbl($u, $n = 256, $m = 16)
{
$h = sprintf("%u", crc32($u));
$h1 = intval($h / $n);
$h2 = $h1 % $n;
$h3 = base_convert($h2, 10, $m);
$h4 = sprintf("%02s", $h3 );
return $h4;
}

The above has introduced the PHP sub-library and sub-table hash algorithm, including relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!