Looking for an ultrafast data store to perform intersect operations

天大地大妈咪最大 提交于 2019-12-05 18:42:43

I suspect that bitmaps are your best hope.

In my experience, redis is a perfect server for bitmaps; you would use the string data structure (one of the five data structures available in redis)

many or perhaps all of the operations you will need to perform are available out-of-the-box in redis, as atomic operations

the redis setbit operation has time complexity of O(1)

In a typical implementation, you would hash your array values to offset values on the bit string, then set each bit at its corresponding offset (or index); like so:

>>> r1.setbit('k1', 20, 1)

the first argument is the key, the second is the offset (index value) and the third is the value at that index on the bitmap.

to find if a bit is set at this offset (20), call getbit passing in the key for the bit string.

>>> r1.getbit('k1', 20)

then on those bitmaps, you can of course perform the usual bitwise operations e.g., logical AND, OR, XOR.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!