Python库,它实现了一个重新备份的Bloom过滤器。

ibloom的Python项目详细描述


伊布卢姆

这是pyreBloom-ng的分支,pyreBloom ng是一个python库,它实现了一个Redis支持的Bloom过滤器。在

布鲁姆真的很强大。但它是设置.py测试和试验台/基准.py都过时了,回购的最后承诺是4年前。在

基于pyreBloom ng ng并添加了python3的str支持,避免了烦人的b'some_key'

安装

先决条件

ibloom需要hiredis库、Cython和{}

hiredis

# Mac
brew install hiredis

# ubuntu
apt-get install libhiredis-dev

# From source:
git clone https://github.com/redis/hiredis
cd hiredis && make && sudo make install

Cython

^{pr2}$

启动

初始化实例

fromibloomimportIBloomib=IBloom('ibloomI',1000,0.01,'127.0.0.1',6383)

或者

fromibloomimportIBloomib_n=IBloom(key='ibloomN',capacity=1000,error=0.01,host='127.0.0.1',port=6383)

检查基本信息

# You can find out how many bits this will theoretically consume>>>ib.bits9585# And how many hashes are needed to satisfy the false positive rate>>>ib.hashes7# find all available bloom filter keys>>>ib.keys()['ibloomI.0']

添加数据

添加所有提供的

# Add one value at a time (slow)>>>ib.add('first')True# Or use batch operations (faster).>>>ib.update([f'{x}'forxinrange(5)])5# Alternative: ib += data, but this will return nothing>>>ib+=[f'{x+5}'forxinrange(5)]

仅在不存在时添加

# will first get the difference, and then update them to redis, and return them>>>ib.update_difference(['5','6','7','8','9','10'])['10']

检查钥匙是否存在

找到一个

# Test one value at a time (slow).# . in ...>>>'first'inibTrue# ...contains(.)>>>ib.contains('first')True

查找多个
# Use batch operations (faster).# Note: ibloom.intersection() returns a list of values# which are found in a Bloom filter. It makes sense when# you consider it a set-like operation.>>>ib.intersection(['3','4','5','6'])['3','4','5','6']# Alternative: ib & [b'3', b'4', b'5', b'6']>>>ib&['3','4','5','6','9','10']['3','4','5','6','9']

查找不存在

>>>ib.difference(['5','6','7','8','9','10'])['10']# not recommended, maybe update in the future# Alternative: ib ^ ['5', '6', '7', '8', '9', '10']>>>ib^['5','6','7','8','9','10']['10']

删除bloom键

# delete selfib.delete()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么会出现这些错误?表达式的非法开始   使用HttpUrlConnection的java测试URL仅适用于前面的www   在大数据集上使用kmeans的java堆外内存   查找Java RandomAccessFile如何以字符形式读取第n个字节   java Android从BroadcastReceiver获取标题和描述   java使用构造函数参数模拟嵌套类并测试方法   正在将Azure Blob项强制转换为Java文件对象   java并行运行testNG套件   java程序在运行时似乎没有进入   贬低Java规则引擎的优点和缺点   文本区域中的java中心文本   java JPA从多个表中选择错误   类Java问题使用类加载器重新加载代码   java如何在Spring非管理类上使用@Value   java(关闭)Gradle导入VS代码失败   java arraylist拆分(“空白”)并计算字数   Android/Java如何在单独的*中调用函数。java文件?   具有基本身份验证的java Apache Camel RSS模块   java为什么程序在出现溢出或下溢时不抛出异常