pleonasm/bloom-filter
Composer 安装命令:
composer require pleonasm/bloom-filter
包简介
A pure PHP implementation of a Bloom Filter
关键字:
README 文档
README
A Bloom Filter for PHP
This is a well tested implementation of a bloom filter for PHP. It has the following features:
- Efficient memory use for bit array (as efficient as PHP can be anyway).
- A way to get a raw version of the filter for transport to other systems.
- Ability to restore said raw filter back into a usable one.
- Auto-calculates optimal hashing and bit array size based on desired set size and false-positive probability.
- Auto-generates hashing functions as needed.
Installation
Install via Composer (make sure you have composer in your path or in your project).
Put the following in your package.json:
{
"require": {
"pleonasm/bloom-filter": "*"
}
}
Run composer install.
Usage
<?php 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
Warnings On Serialization
As a note: using json_encode() on a bloom filter object should work across
most systems. You can run in to trouble if are moving the filter between 64
and 32 bit systems (that will outright not work) or moving between
little-endian and big-endian systems (that should work, but I haven't tested
it).
Also note that json_encode() will take the binary bit array and base64
encode it. So if you have a large array, it will get about 33% bigger on
serialization.
Other Notes
Under the hood, the hashing mechanism used is actually an HMAC of whatever algorithm you pick. In general, PHP's hash extension is not happy if you pick a non-cryptographically secure algo to calculate an HMAC so just don't do it with this library and everything will work just fine.
This may not come up if you're using PHP 7.1 specifically, but generally the hash you use must output at least 64 bits. Things like adler32 or crc32 not okay to use even if they don't throw an error in PHP 7.1.
Requirements
The latest release of this project requires PHP 8.0 or newer.
Version 1.0.3 of pleonasm/bloom-filter is available for PHP 7.1+.
Version 1.0.2 of pleonasm/bloom-filter is available for PHP 5.4 to 7.0.
License
You can find the license for this code in the LICENSE file.
pleonasm/bloom-filter 适用场景与选型建议
pleonasm/bloom-filter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 766.56k 次下载、GitHub Stars 达 71, 最近一次更新时间为 2013 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filter」 「Bloom Filter」 「sets」 「bloom」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pleonasm/bloom-filter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pleonasm/bloom-filter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pleonasm/bloom-filter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nova searchable filter for belongsTo relationships.
Simple minimal but useful set of utils (properties, strings, datetimes, etc.)
Nested Set Model for Laravel 12+ (Lunar-maintained fork of kalnoy/nestedset)
Symfony DataGridBundle
Data provider for yii2
This Laravel Nova package allows you to detach filters from the filter dropdown
统计信息
- 总下载量: 766.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 78
- 点击次数: 23
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2013-05-27