Bloom filters and other filter algorithms based on memory and redis
Project description
由python实现的一系列高效的过滤器算法实现
- 基于redis和memory
- 低时间复杂度
Useage
from pyfilters import MemoryBloomFilter
bf = MemoryBloomFilter(10000, 0.00001)
for i in range(1000):
bf.add(i)
for i in range(1000):
assert i in bf
assert 1001 not in bf
Advanced usage
- 计数形布隆过滤器,可以删除数据
from pyfilters import CountMemoryBloomFilter
cbf = CountMemoryBloomFilter(10000, 0.00001)
for i in range(1000):
cbf.add(i)
for i in range(1000):
assert i in cbf
cbf.remove(1)
assert 1 not in cbf
- redis分块布隆过滤器,避免单key过大
from redis import Redis
from pyfilters import ChunkedRedisBloomFilter
bf = ChunkedRedisBloomFilter(Redis(), "test_bloomfilter", 10000, 0.00001)
for i in range(1000):
bf.add(i)
for i in range(1000):
assert i in bf
assert 1001 not in bf
- 分块计数形redis布隆过滤器,可以删除数据
from redis import Redis
from pyfilters import CountRedisBloomFilter
rcbf = CountRedisBloomFilter(Redis(), "test_countbloomfilter", 10000, 0.00001)
for i in range(1000):
rcbf.add(i)
for i in range(1000):
assert i in rcbf
rcbf.remove(1)
assert 1 not in rcbf
asyncio兼容
在pyfilters.asyncio包
import asyncio
from aioredis import Redis
from pyfilters.asyncio import CountRedisBloomFilter
async def main():
rcbf = CountRedisBloomFilter(Redis(), "test_countbloomfilter", 10000, 0.00001)
for i in range(1000):
await rcbf.add(i)
for i in range(1000):
assert await rcbf.contains(i)
await rcbf.remove(1)
assert not await rcbf.contains(1)
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyfilters-0.1.3.tar.gz
(10.1 kB
view details)
Built Distribution
pyfilters-0.1.3-py3-none-any.whl
(11.4 kB
view details)
File details
Details for the file pyfilters-0.1.3.tar.gz
.
File metadata
- Download URL: pyfilters-0.1.3.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57c41db9ac298ff83e4be4051121d1397fd712853327477ff0185b77871473ec |
|
MD5 | 1257ad8b55e95acd9d5e530c3f32a8c5 |
|
BLAKE2b-256 | 2427e3103d44f5bf61fbf587a6b8a7f97b0dd743805579244011705ba22a967a |
File details
Details for the file pyfilters-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: pyfilters-0.1.3-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a54a3f0b1e909545561f76307a5779ecd789dcdb5ad7e23116298ac94eb1b97 |
|
MD5 | a6ceb66e2543dde57ded6f6c74d8dc40 |
|
BLAKE2b-256 | 2fe1694cecef26b3fcae42623e460fbd12fa6d4a6a9fc230418c07d227a9ecc1 |