コード例 #1
0
ファイル: counter.php プロジェクト: razorpay/php-bloom-filter
<?php

require '../bloom.class.php';
define('NL', "<br>\r\n");
/*
* Init object for 10 entries
* counter option is required for delete ability but it much slower
**/
$bloom = new Bloom(array('entries_max' => 10, 'counter' => true));
while (count($vars) < 10) {
    $vars[] = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5);
}
/*
* Set 10 values to object
**/
$bloom->set($vars);
/*
* Check existance of one object, return boolean
**/
echo $bloom->has($vars[rand(0, count($vars) - 1)]), NL;
/*
* Check existance of one object, return number of Hashes aprovemts
**/
echo $bloom->has($vars[rand(0, count($vars) - 1)], false), NL;
/*
* Check existance of many objects, return boolean
**/
echo json_encode($bloom->has(array_slice($vars, 0, 6))), NL;
/*
* Check existance of many objects, return number of Hashes aprovemts
**/
コード例 #2
0
<?php

require '../bloom.class.php';
require 'other/labloom/bloom.php';
define('NL', "<br>\r\n# ");
/*
	taskaz / labloom
	https://github.com/taskaz/labloom
*/
$number = (int) $_GET['number'] ? (int) $_GET['number'] : 1000;
/*
* Init object for $num entries
**/
$bloom = new Bloom(array('entries_max' => $number, 'error_chance' => 0.01, 'hash' => array('strtolower' => false)));
$foe = new LaBloom('123', $bloom->entries_max);
while (count($vars) < $number) {
    $vars[] = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz"), 0, 10);
}
/*
* Insert to bloom 
**/
$stat['bloom']['insert']['s'] = get_stat();
$bloom->set($vars);
$stat['bloom']['insert']['e'] = get_stat();
/*
* Insert to array
**/
$stat['foe']['insert']['s'] = get_stat();
//for( $i = 0; $i < $number; $i++ )
$foe->add($vars);
$stat['foe']['insert']['e'] = get_stat();
コード例 #3
0
ファイル: caching.php プロジェクト: razorpay/php-bloom-filter
<?php

require '../bloom.class.php';
define('NL', "<br>\r\n");
/*
* Setting up object takes a lot of time (much of it takes insertation)
* So you can just cache the hole object
**/
$bloom = new Bloom(array('entries_max' => 10));
while (count($vars) < 10) {
    $vars[] = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5);
}
/*
* Set 10 values to object
**/
$bloom->set($vars);
file_put_contents('bloom.cache', serialize($bloom));
$bloom = null;
$bloom = unserialize(file_get_contents('bloom.cache'));
/*
* Check existance of one object, return boolean
**/
echo $bloom->has($vars[rand(0, count($vars) - 1)]), NL;
/*
* Check existance of one object, return number of Hashes aprovemts
**/
echo $bloom->has($vars[rand(0, count($vars) - 1)], false), NL;
/*
* Check existance of many objects, return boolean
**/
echo json_encode($bloom->has(array_slice($vars, 0, 6))), NL;