分库分表hash算法

function hash_datebase($u, $s = 4)
{
    $h = sprintf("%u", crc32($u));
    $h1 = intval(fmod($h, $s));
    return $h1;
}
 
 
for($i=1;$i<100;$i++)
{
echo hash_datebase($i);
echo "<br>";
}
 
function hash_table($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;
}

你可能感兴趣的:(分库分表hash算法)