Java byte array to RoaringBitmap

17 views
Skip to first unread message

Shikhar Singh

unread,
Aug 4, 2023, 7:20:29 AM8/4/23
to Roaring Bitmaps
Is there a implemented way to convert a bitset represented as a byte array to a roaringbitmap?
Similar to: Bitset.valueOf(byte[] bytes)

I couldn't find any way to achieve this without additional memory copying OOTB.

As of now, I am replicating Bitset.valueOf(byte[] bytes) implementation. 
The reason is the bitmap is being persisted in Redis. I can't keep it in Roaring form as then it will be much more difficult to write atomically, so data is persisted kept as an uncompressed bitset. I guess such a pattern makes sense for many data storage too. (on-disk uncompressed, in-memory Roaring).

So I feel it makes sense to have such a helper method in RoaringBitmap code itself.

Happy to contribute code.

Daniel Lemire

unread,
Aug 4, 2023, 10:50:48 AM8/4/23
to Roaring Bitmaps
As of now, I am replicating Bitset.valueOf(byte[] bytes) implementation.

Pull request invited. Please provide complete tests.

In C (in the CRoaring library), we have functions that allow you to go from a Roaring Bitmap to a standard bitset :

roaring_bitmap_t *r1 = roaring_bitmap_create(); 
for (uint32_t i = 100; i < 100000; i+= 1 + (i%5)) { roaring_bitmap_add(r1, i); } 
bitset_t * bitset = bitset_create(); 
bool success = roaring_bitmap_to_bitset(r1, bitset);

Shikhar Singh

unread,
Aug 7, 2023, 2:29:42 AM8/7/23
to Roaring Bitmaps
Here you go: https://github.com/RoaringBitmap/RoaringBitmap/pull/650/files

Adds a very low memory method to create a  RoaringBitmap from a ByteBuffer (or a byte array), representing the uncompressed bitmap
Should be useful for performance sensitive cases as RoaringBitmap can be created from bytes directly read from the network, with no additional copying.

I have added tests and benchmarks. Do tell if I messed up somewhere.

Daniel Lemire

unread,
Aug 7, 2023, 11:42:55 AM8/7/23
to Shikhar Singh, Roaring Bitmaps
It is a good PR and I expect we will merge after some tuning.

--
You received this message because you are subscribed to the Google Groups "Roaring Bitmaps" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roaring-bitma...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/roaring-bitmaps/2c94d49d-8dcd-4ff5-ad56-faf7833e29d1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages