php布隆过滤计算

<?php
/**
 *
 * @param $k 哈希函数个数
 * @param $m bit array 位数
 * @param $n 短语数
 **/
function bloomFilterFP($k, $m=512, $n=8192){
	$e = 2.718282;
	$exponent1 = -($k*($n+0.5)/($m-1));
	$base = 1 - pow($e, $exponent1);
	$rs = pow($base, $k);
	return $rs;
}

function getBestK($m,$n){
	return ($m/$n)*log(2);
}
$m = $_GET['m'];
$n = $_GET['n'];
$k=getBestK($m,$n);
echo $k;
$k = ceil($k);
echo '<br>';
echo $k;
echo '<br>';
echo bloomFilterFP($k,$m,$n);

  

posted @ 2021-01-13 10:43  goldenstones  阅读(114)  评论(0编辑  收藏  举报