PHP code example of pleonasm / bloom-filter
1. Go to this page and download the library: Download pleonasm/bloom-filter library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pleonasm / bloom-filter example snippets
use Pleo\BloomFilter\BloomFilter;
$approximateItemCount = 100000;
$falsePositiveProbability = 0.001;
$before = memory_get_usage();
$bf = BloomFilter::init($approximateItemCount, $falsePositiveProbability);
$after = memory_get_usage();
// if this were a 100,000 item array, we would be looking at about 4MB of
// space used instead of the 200k or so this uses.
echo ($after - $before) . "\n";
$bf->add('item1');
$bf->add('item2');
$bf->add('item3');
$bf->exists('item1'); // true
$bf->exists('item2'); // true
$bf->exists('item3'); // true
// The following call will return false with a 0.1% probability of
// being true as long as the amount of items in the filter are < 100000
$bf->exists('non-existing-item'); // false
$serialized = json_encode($bf); // you can store/transfer this places!
unset($bf);
// Re-hydrate the object this way.
$bf = BloomFilter::initFromJson(json_decode($serialized, true));
$bf->exists('item1'); // still true
$bf->exists('item2'); // still true
$bf->exists('item3'); // still true
$bf->exists('non-existing-item'); // still false