-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: RoaringBitmap::from_lsb0_bytes
#288
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @lemolatoon 👋
Thank you very much for these changes. The results look very good, indeed. However, could you:
- Write a better explanation of what
offset
means. I understand, but it needs to be clearer. Maybe talk about internal containers that are aligned around 64k values integer groups? - Explain what kind of input is expected in plain text in the function description (endianness, size, alignment).
- Move this function and the test into the serialization module.
Thank you very much for the work!
83af352
to
adbc00b
Compare
Hi @Kerollmops 👋 Thank you for your quick reply. I have just made changes based on your review. Basically I did:
|
adbc00b
to
af5ea01
Compare
af5ea01
to
03a61ad
Compare
@Dr-Emann I've just fixed the documentation and made the implementation endian-aware. |
I applied @Kerollmops I would like you to review this pull requests, then I can see the CI result. |
RoaringBitmap::from_bitmap_bytes
RoaringBitmap::from_lsb0_bytes
Hey @lemolatoon 👋 Sorry for the very late reply. I just approved your changes so that you can see the CI. |
Thank you @Kerollmops ! |
@lemolatoon The CI errors should be fixed by pulling in main, thanks to #293. |
2706bd9
to
ac672a5
Compare
I |
It seems to have the clippy warnings appeared only in 1.66.0 not in stable. I fixed the warnings. Could you re-run CI again please? @Kerollmops |
Hey @lemolatoon 👋 Would you mind rebasing on main, please? I just merged #295. Have a nice one 🐿️ |
e72b0fc
to
915e582
Compare
@Kerollmops
I am afraid to bother you multiple times, but I'd like to see the CI result again 🙏 |
I accidentally skipped one commit fixing the cargo clippy warning by the last rebase. I fixed the warning again and pushed. |
roaring/src/bitmap/serialization.rs
Outdated
pub fn from_lsb0_bytes(offset: u32, mut bytes: &[u8]) -> RoaringBitmap { | ||
assert_eq!(offset % 8, 0, "offset must be a multiple of 8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we can't just switch this offset in bits to an offset in bytes as the precision can only be expressed 8 bits at a time. This way we avoid this assert and reduce the possible errors.
If I understand correctly the offset is like a helper to increment the bitmap numbers by 8 at a time? Why is it necessary that it must be 8 at a time? Do we want to keep this? Why users can't just shift numbers themselves?
And if we want to keep it can we make it more clear (like the description I did above)? Your example helped me understand the high intent of this parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review and sorry for the late responce.
The reason why the offset must be 8 multiples is if the function accepts not 8 multiples offset, the copying will not so easy. If the container is Array, the implementation would be almost the same. In case Bitmap store, we need bit shifting for every bitmap byte copy.
We can switch the implementation based on the offset. In terms of the peformance, the users who use 8 multiples offset might not be impacted by this API change.
And the peformance of users with not 8 multiples offset is unknown.
I could allow any offset for this method with a little additional implementation and the document on peformances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @lemolatoon, for the explanation. It would be great if we could accept for than just 8 multipliers, indeed.
* Directly create an array/bitmap store based on the count of bits * Use u64 words to count bits and enumerate bits * Store in little endian, then just fixup any touched words * Only use unsafe to reinterpret a whole bitmap container as bytes, everything else is safe * Allow adding bytes up to the last possible offset
we can setting an initial value in that case
2a9a0c2
to
a10a29c
Compare
I added the implementation of the work around for non-8-multiple offset for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much, @lemolatoon 👍
That's excellent work, and you can even help me with #301. I accept your changes and will release a new, non-breaking version soon!
Have a nice end of the week 😊
Thank you for merging, releasing a new version, and the advice for this pull request! |
The Feature Explanation
RoaringBitmap
Function Behavior
RoaringBitmap
offset
can be used to offset the passing bitmap's indexoffset
is not aligned to # of bits ofContainer
'sStore::Bitmap
(# of bits ofBox<[u64; 1024]>
), this function panicsMotivation
Sometimes bitmap is calculated by SIMD instructions. The result of SIMD instruction is likely to be already bitmask, not the series of bitmap indicies.
Under current implementation, when you intend use
RoaringBitmap
with bitmask produced by SIMD instruction, you have to useRoaringBitmap::sorted_iter
or just insert one by one.To solve this problem, I implemented
RoaringBitmap::from_bitmap_bytes
, which can be used to construct directly from bitmask.Example of Production of Bitmask by SIMD instructions
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=40ddd13554c171be31fe53893401d40f
Benchmark Result
On my laptop (Apple M3 MacBook Air Sonoma14.3 Memory 16 GB), in most cases
from_lsb0_bytes
is much faster thanfrom_sorted_iter
.Part of Results