-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBloomTests.php
53 lines (37 loc) · 991 Bytes
/
BloomTests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require('BloomFilter.php');
function getRandomString($length) {
$alphabet = 'abcdefghijklmnopqrstuvwxyz';
$s = '';
for ($i = 0; $i < $length; $i++){
list($usec, $sec) = explode(' ', microtime());
$seed = (float) $sec + ((float) $usec * 100000);
mt_srand($seed);
$s .= $alphabet[mt_rand(0,25)];
}
return $s;
}
/*
$bf = new BloomFilter(3000000);
$f = fopen('/usr/share/dict/words','r');
while(!feof($f)) $bf->add(trim(fgets($f)));
file_put_contents('bloom',$bf->field);
//*/
/*
$bf = BloomFilter::init(file_get_contents('bloom'));
echo $bf->len."\n";
$test_words = array('this','library','does','bloom','filters','in','php');
foreach ($test_words as $word) if ($bf->has($word)) echo $word."\n";
//*/
/*
$bf = BloomFilter::init(file_get_contents('bloom'));
while (++$i<=10000) {
$word = getRandomString(8);
if ($bf->has($word)) echo $word."\n";
}
//*/
/*
$bf = BloomFilter::init(file_get_contents('bloom'));
echo $bf->falsePositiveRate(95000)."\n";
//*/
?>