zqhong / bloom-filter
此包最新版本(v1.0.0)没有可用的许可信息。
Bloom 过滤器的实现
v1.0.0
2019-06-25 13:51 UTC
Requires
- php: ~7.0
Requires (Dev)
- phpunit/phpunit: ^6.1
This package is auto-updated.
Last update: 2024-09-26 01:37:35 UTC
README
Bloom 过滤器是一种空间效率高的概率数据结构,由Burton Howard Bloom于1970年提出,用于测试一个元素是否为集合的成员(可能存在假阳性匹配,但不存在假阴性匹配)。
<?php use \RocketLabs\BloomFilter\Persist\Redis; use \RocketLabs\BloomFilter\BloomFilter; use \RocketLabs\BloomFilter\Hash\Murmur; use \RocketLabs\BloomFilter\Persist\BitString; $setToStore = [ 'Test string 1', 'Test string 2', 'Test string 3', 'Test string 4', 'Test string 5', ]; $redisParams = [ 'host' => 'localhost', 'port' => 6379, 'db' => 0, 'key' => 'bloom_filter', ]; $persisterRedis = Redis::create($redisParams); $persisterInRam = new BitString(); $filter = new BloomFilter($persisterRedis, new Murmur()); $filter->setSize(count($setToStore)); foreach ($setToStore as $string) { $filter->add($string); } if ($filter->has('Test string 1')) { echo 'Possibly in set"' . PHP_EOL; } else { echo 'Definitely not in set' . PHP_EOL; }