aviggiano / redis-roaring

Roaring Bitmaps for Redis
MIT License
348 stars 56 forks source link

Cann't flip a bitmap by range #73

Closed jiangtao244 closed 3 years ago

jiangtao244 commented 4 years ago

Need to pass “last“” from R.BITOP NOT

https://github.com/aviggiano/redis-roaring/blob/860282da7117562bd9dc38c8ccde57be755b2260/src/data-structure.c#L91

aviggiano commented 4 years ago

Hello, thank you for opening this issue.

Can you explain the problem in more detail? Do you have an example that I can use to reproduce?

Thanks

jiangtao244 commented 4 years ago

For example: Now I have ten users, and the number of users is increasing. login_monday = [ 1, 3, 5, 8, 9 ] login_tuesday = [ 1, 2, 4, 6, 8]

I want to get the users login on monday but not login on tuesday. I need to flip login_tuesday and expect [ 0, 3, 5, 7, 9 ], but get [0, 3, 5, 7] by using R.BITOP NOT

Now I have to use a redis transaction to achive this goal:

  1. R.BITSET login_tuesday 9 1
  2. R.BITOP NOT dest login_tuesday
  3. R.BITSET login_tuesday 9 0

This's Ugly.

aviggiano commented 4 years ago

I was able to test this and can confirm this is not the intended behavior. What do you think about this change? Passing last as an optional parameter, such as R.BITOP NOT destkey srckey last? This would be the expected output:

> R.SETINTARRAY login_monday 1 3 5 8 9
OK
> R.SETINTARRAY login_tuesday 1 2 4 6 8
OK
> R.MAX login_monday
(integer) 9
> R.NOT login_monday
(integer) 9
> R.BITOP NOT not_login_tuesday login_tuesday 9
(integer) 5
> R.BITOP AND final login_monday not_login_tuesday
(integer) 5
> R.GETINTARRAY final
1) (integer) 0
2) (integer) 3
3) (integer) 5
4) (integer) 7
5) (integer) 9
jiangtao244 commented 4 years ago

Yes, we can change like this.

aviggiano commented 3 years ago

Closing this since it seems it was already resolved on #77 and #78