MySQL的位运算,布隆过滤器 [英] MySQL bitwise operations, bloom filter

查看:1271
本文介绍了MySQL的位运算,布隆过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个布隆过滤器使用MySQL(其他建议的替代)。

I'd like to implement a bloom filter using MySQL (other a suggested alternative).

问题是如下:

假设我有一个存储的8位整数表,这些以下值:

Suppose I have a table that stores 8 bit integers, with these following values:

1: 10011010
2: 00110101
3: 10010100
4: 00100110
5: 00111011
6: 01101010

我想找到是按位全部结果和这样的:

I'd like to find all results that are bitwise AND to this:

00011000

结果应该是行1和5。

The results should be rows 1 and 5.

不过,我的问题,他们不是8位整数,而是n位整数。我如何保存这一点,我怎么查询?速度是关键。

However, in my problem, they aren't 8 bit integers, but rather n-bit integers. How do I store this, and how do I query? Speed is key.

推荐答案

为int的列创建一个表(使用的此链接挑右INT大小)。不要数字存储为0和1序列

Create a table with int column (use this link to pick the right int size). Don't store numbers as a sequence of 0 and 1.

有关你的数据会看起来像这样:

For your data it will look like this:

number

154
53
148
38
59
106

和你需要找到匹配24的所有条目。

and you need to find all entries matching 24.

然后你可以运行像

SELECT * FROM test WHERE number & 24 = 24

如果你想避免皈依到应用程序中的10基数你可以把它交给MySQL的:

If you want to avoid convertion into 10 base numbers in your application you can hand it over to mysql:

INSERT INTO test SET number = b'00110101';

和搜索这样的

SELECT bin(number) FROM test WHERE number & b'00011000' = b'00011000'

这篇关于MySQL的位运算,布隆过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆