PHP code example of makinacorpus / php-bloom

1. Go to this page and download the library: Download makinacorpus/php-bloom 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/ */

    

makinacorpus / php-bloom example snippets


// You may cache this value, and fetch it back, it's the whole goal of this
// API. Beware that the stored string might contain ``\0`` characters, ensure
// your storage API deals with those strings in safe way.
$value = null;

// Configure your Bloom filter, if you store the value, you should store the
// configuration along since selected hash algorithms and string size would
// change otherwise.
$probability = 0.0001
$maxSize = 10000;

$filter = new \MakinaCorpus\Bloom\BloomFilter();

// You may add as many elements as you wish, elements can be any type, really,
// if not scalar they will be serialized prior to being hashed.
$filter->set('some_string');
$filter->set(123456);
$filter->set(['some' => 'array']);
$filter->set(new \stdClass());

// And the whole goal of it:
if ($filter->check('some_value')) {
  do_something();
}