maxwilms / bloom-filter
Bloom filter - a space-efficient probabilistic data structure for PHP 5.4+
Installs: 11 756
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
Requires (Dev)
- behat/behat: ~3.0
- phpspec/phpspec: ~2.5
This package is not auto-updated.
Last update: 2024-12-17 03:40:57 UTC
README
A Bloom filter is a probabilistic data structure, that tests whether an element is member of a set. It will always confirm if the element is member of the set. But false-positives are possible.
When to use Bloom filters
Use this data structure when you quickly need to confirm that a certain value does not exists in a large data set. For example a certain row is not present on your database (e.g., IP address, username, email).
Installation
First install composer.
Require the bloom filter via composer:
composer require maxwilms/bloom-filter
Now you are ready to use it!
Usage
<?php require_once('vendor/autoload.php'); use maxwilms\BloomFilter\BloomFilterGenerator; // generate a bloom filter for 1000 elements with a probability of 1% for false positives $bloomFilter = BloomFilterGenerator::generate(1000, 0.01); $bloomFilter->add('foo'); $bloomFilter->add('bar'); // ... add more $bloomFilter->contains('foo'); // true - possibly in set $bloomFilter->contains('baz'); // false - definitely not in set
TODO
more examples :)