You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a format call 'GRIB' there is bitmap section, so far i used a classic java Bitset but on some files it takes a lot of memory.
So I'm trying to use RoamingBitmap instead, but at writing I didn't find any way to get a compact byte[] as in Bitset.toArray.
Maybe I missing it, something like :
BitSet bs = BitSetUtil.toBiset(RoamingBitmap)
Or maybe there is somekind of serializer ? How do you suggest it could be done in a efficient way (looping on all int to rebuild the byte[] would obviously be inefficient) ?
Description copied from interface: [ImmutableBitmapDataProvider](https://github.com/RoaringBitmap/RoaringBitmap/issues/ImmutableBitmapDataProvider.html#serialize(java.nio.ByteBuffer))
Serialize this bitmap to a ByteBuffer. This is the preferred method to serialize to a byte array (byte[]) or to a String (via Base64.getEncoder().encodeToString).. Irrespective of the endianess of the provided buffer, data is written using LITTlE_ENDIAN **as per the RoaringBitmap specification**. The current bitmap is not modified.
this looks like it generates a custom serialization byte array.
Or do you confirm it will produce the same output as BitSet.toByteArray() ?
Ah, my bad. I thought you just wanted a serialised version you can store in a GRIB file.
I don't believe RoaringBitmap has an API to convert into a bitset representation, beyond just iterating through all the values, adding them into a bitset and calling toByteArray() on that.
You could add a new method for this in a PR, that at least for containers that are already bitset encoded gives you better performance, but it'd still have to essentially go through this step (or something similar) for array and RLE containers.
And of course you'd immediately lose your size reduction benefits from using RoaringBitmap in the first place again. So I think the real question is, if this conversion can't somehow be avoided on your side? If not, using RoaringBitmap may not make a lot of sense in your use case.
Ok, that makes sense.
Would it be possible, instead of materialising the entire byte[] from the RoaringBitmap at once, to perhaps materialise container by container and immediately write that out into the GRIB file? That would avoid the sudden blow-up, allow you to reuse the allocated byte[] (since all containers are the same size), and there should already be functions in RoaringBitmap to turn any container into a bitmap container, so I think it'd be fairly easy to implement in a PR.
You are likely right, but I don't have the time, I'm new with RoaringBitmap. I'm a user here with a few allocated hours to fix an out of memory exception in a project. But I do work/contribute on other Open-Source projects (Apache-SIS,GeoAPI,GeotoolKit,Examind,Unlicense-lib...).
But now that RoaringBitMap has set a foot in Examind and that we use a lot of bitmap (because we(Geomatys) make cartography tools) It's likely in the futur we will submit more issues and/or PR.
Please look at the patch that supports the conversion to bitset which makes it easy to create an uncompressed version. @RickMoynihan@lemire please take a look. Appreciate your time.
Activity
larsk-db commentedon Mar 29, 2022
You are looking for
bitmap.serialize(buffer)I believe? Something like:jsorel commentedon Mar 29, 2022
The doc is not very clear :
this looks like it generates a custom serialization byte array.
Or do you confirm it will produce the same output as BitSet.toByteArray() ?
jsorel commentedon Mar 29, 2022
Just made a test :
output is :
Which is not what I expected, a single bit set at offset 1000.
Any other solution ?
larsk-db commentedon Mar 29, 2022
Ah, my bad. I thought you just wanted a serialised version you can store in a GRIB file.
I don't believe RoaringBitmap has an API to convert into a bitset representation, beyond just iterating through all the values, adding them into a bitset and calling
toByteArray()on that.jsorel commentedon Mar 29, 2022
That's what I have for now, but it does look really inefficient.
larsk-db commentedon Mar 29, 2022
It certainly is.
You could add a new method for this in a PR, that at least for containers that are already bitset encoded gives you better performance, but it'd still have to essentially go through this step (or something similar) for array and RLE containers.
And of course you'd immediately lose your size reduction benefits from using RoaringBitmap in the first place again. So I think the real question is, if this conversion can't somehow be avoided on your side? If not, using RoaringBitmap may not make a lot of sense in your use case.
jsorel commentedon Mar 29, 2022
I have no choice, the GRIB Format is well defined, it's a standard
https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/
We loose in memory, but it's only when writing it back in GRIB, when file is loaded it uses far less then a BitSet, so it's worth it.
After a benchmark, we drop from 3.83Mo to 194Ko
With BitSet :

With RoaringBitmap :

larsk-db commentedon Mar 29, 2022
Ok, that makes sense.
Would it be possible, instead of materialising the entire
byte[]from the RoaringBitmap at once, to perhaps materialise container by container and immediately write that out into the GRIB file? That would avoid the sudden blow-up, allow you to reuse the allocatedbyte[](since all containers are the same size), and there should already be functions in RoaringBitmap to turn any container into a bitmap container, so I think it'd be fairly easy to implement in a PR.jsorel commentedon Mar 29, 2022
You are likely right, but I don't have the time, I'm new with RoaringBitmap. I'm a user here with a few allocated hours to fix an out of memory exception in a project. But I do work/contribute on other Open-Source projects (Apache-SIS,GeoAPI,GeotoolKit,Examind,Unlicense-lib...).
But now that RoaringBitMap has set a foot in Examind and that we use a lot of bitmap (because we(Geomatys) make cartography tools) It's likely in the futur we will submit more issues and/or PR.
Thanks for the help.
richardstartin commentedon Mar 29, 2022
Let's leave this open since it's generally useful, and it could probably be implemented in less than an hour for someone familiar with the code.
[-]RoamingBitmap to BitSet/byte[][/-][+]RoamingBitmap to Uncompressed BitSet/byte[][/+]lemire commentedon Mar 29, 2022
You'd probably want to go in both directions (serialize to uncompressed bitset and back).
sakinapelli commentedon Mar 30, 2023
patch.diff.zip
Please look at the patch that supports the conversion to bitset which makes it easy to create an uncompressed version.
@RickMoynihan @lemire please take a look. Appreciate your time.
RoaringBitmap to BitSet/long[]/byte[]. Fixes RoaringBitmap#556
RoaringBitmap to BitSet/long[]/byte[]. Fixes RoaringBitmap#556
RoaringBitmap to BitSet/long[]/byte[]. Fixes RoaringBitmap#556
RoaringBitmap to BitSet/long[]/byte[]. Fixes RoaringBitmap#556
RoaringBitmap to BitSet/long[]/byte[]. Fixes RoaringBitmap#556
RoaringBitmap to BitSet/long[]/byte[] (RoaringBitmap#713)