RoaringBitmap / roaring-rs

A better compressed bitset in Rust
https://docs.rs/roaring/
Apache License 2.0
743 stars 82 forks source link

"Moving" parts of a RoaringBitmap #276

Open llogiq opened 3 months ago

llogiq commented 3 months ago

Let's say I have a RoaringBitmap with the values 0, 1, 32, 35 and 70. Now I want to reduce all values > 6 and < 40 by, say, 2. Is there a thing I'm overlooking or would I have to remove and recreate the values via from_sorted_iter?

Kerollmops commented 3 months ago

Hey @llogiq 👋

Happy to see you there. Unfortunately, there is no direct operation to do the following. What I would do is create a second bitmap with numbers in between 7 (> 6) and 39 (<40), do an intersection to get the real numbers. Do the increment by 2 by by iterating on this subset and creating a new bitmap (yes, again). Using the RoaringBitmap::remove_range method to delete the range of values in between 7 and 39 then do the union with the previously shifted bitmap (using the BitOrAssign operator).

What are we Missing to be Efficient?

llogiq commented 3 months ago

Yeah, I guess having RoaringBitmap::{in, de}crement_range functions would probably get the most bang for the buck, and could also easily be SIMD-optimized.