Read Only view of a RoaringBitmap

21 views
Skip to first unread message

Shikhar Singh

unread,
Nov 14, 2023, 11:45:34 PM11/14/23
to Roaring Bitmaps
Do we have a way to share a "read-only" view of a memory backed RoaringBitmap?

Expectations:
- all calls should be backed by an underlying bitmap 
- any calls that modify the bitmap throw a documented exception

Usecase:
I have a RoaringBitmap that needs to be move around throughout the codebase for operations that aren't expected to modify it.
Modifications should only happen by a holder object based on some internal logic.

A way to enforce this "read-only" behaviour by design and without any unnecessary object allocs/copies whenever the bitmap is asked for will make it easier to catch implementation bugs while keeping same performance.

Happy to contribute!

Regards,
Shikhar

Shikhar Singh

unread,
Nov 14, 2023, 11:48:47 PM11/14/23
to Roaring Bitmaps
The way I am thinking is having a wrapper ReadOnlyRoaringBitmap class that delegates all read methods to underlying bitmap and causes an exception on any modify calls.

And exposing a new method in RoaringBitmap: asReadOnly() which returns a cached object (created lazily when first asked for)

I see we have something in the buffer based impl (Immutable* and Mutable*) with similar motivations. The above impl will be a lot simpler though.

Daniel Lemire

unread,
Nov 15, 2023, 11:10:20 AM11/15/23
to Roaring Bitmaps
Just use an ImmutableBitmapDataProvider.

ImmutableBitmapDataProvider readonly = (ImmutableBitmapDataProvider) mybitmap;

And you are done.

Shikhar

unread,
Nov 15, 2023, 11:12:18 AM11/15/23
to Daniel Lemire, Roaring Bitmaps
Awesome, thank you so much!

--
You received this message because you are subscribed to a topic in the Google Groups "Roaring Bitmaps" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/roaring-bitmaps/F3f2b_orjrM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to roaring-bitma...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/roaring-bitmaps/e2e40cba-2344-425d-aa66-35c2c38fa0f5n%40googlegroups.com.

Shikhar

unread,
Nov 15, 2023, 11:23:29 AM11/15/23
to Daniel Lemire, Roaring Bitmaps
Doesn’t exactly meet the expectations I had

As the returned type won’t  be a RoaringBitmap  so can’t be used with other RoaringBitmaps without dirty cast code (which also kind of defeats the purpose). 
Think using ops like and, andNot of any other bitmaps where this bitmap needs to be given as input. Or even the static bit wise like ops that do things out-of-place

Please advice 
Reply all
Reply to author
Forward
0 new messages