Skip to main content

Bloom filters and other filter algorithms based on memory and redis

Project description

由python实现的一系列高效的过滤器算法实现

pypi python implementation wheel license

  • 基于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 redis.asyncio 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


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.5.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

pyfilters-0.1.5-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file pyfilters-0.1.5.tar.gz.

File metadata

  • Download URL: pyfilters-0.1.5.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for pyfilters-0.1.5.tar.gz
Algorithm Hash digest
SHA256 eaafe5948e0cd0c26e9dc26da38987d26d4313f4adcacd6daca640cc206d98c4
MD5 0488dc7e679192f24d3b4f63873e4cc2
BLAKE2b-256 e726c9692e1f65a17145e55eceaca7b08710bd314b8ccd9e46432ca735750d6b

See more details on using hashes here.

File details

Details for the file pyfilters-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pyfilters-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for pyfilters-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 17473c37a1d1266fd9db6be61daaf49a49501d0a6ed813fb8cacbb17e7c876c8
MD5 913a7165feb68f49ae9a8cae75ff8e73
BLAKE2b-256 208e82e769cac03199c3a69bb8f1d4c6a6d65b2cc15a92aa5bb3d03b95b9d9db

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page