Example #1
0
<?php

use Razorpay\BloomFilter\Bloom;
$number = 1000;
/*
* Init object for $num entries
**/
$bloom = new Bloom(array('entries_max' => $number, 'error_chance' => 0.01, 'counter' => true, 'hash' => array('strtolower' => false)));
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['array']['insert']['s'] = get_stat();
for ($i = 0; $i < $number; $i++) {
    $array[] = $vars[$i];
}
$stat['array']['insert']['e'] = get_stat();
while (count($check) < $number / 2) {
    $check[] = substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
}
/*
* Check existance with bloom
**/
Example #2
0
 public function testFilledCacheTest()
 {
     $params = array('counter' => true);
     $bloom_counter = new Bloom(array('counter' => true, 'entries_max' => 10));
     $bloom_default = new Bloom(array('entries_max' => 10));
     for ($i = 0; $i < 10; $i++) {
         $vars[] = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5);
         $res[] = true;
     }
     $bloom_counter->set($vars);
     $bloom_default->set($vars);
     $bloom = array('counter' => $bloom_counter, 'default' => $bloom_default);
     file_put_contents('/tmp/counter', serialize($bloom['counter']));
     file_put_contents('/tmp/default', serialize($bloom['default']));
     $set_counter = $bloom_counter->set;
     $set_default = $bloom_default->set;
     $bloom_counter = null;
     $bloom_default = null;
     $bloom_counter = unserialize(file_get_contents('/tmp/counter'));
     $bloom_default = unserialize(file_get_contents('/tmp/default'));
     $this->assertEquals($res, $bloom_counter->has($vars));
     $this->assertEquals($res, $bloom_default->has($vars));
 }