metamx / bytebuffer-collections

ByteBuffer collection classes for java and jvm-based languages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImmutableBitmap.get(int value) behaves differently for Concise and Roaring

jon-wei opened this issue · comments

Suppose I have a bitmap with bits 0,4,9 set.

When using Concise-backed ImmutableBitmap, if I call bitmap.get(9), I get an IndexOutOfBoundsException.

The get() function seems to expect get(2), if I want to read the value for bit 9, i.e., the value input is treated as a position within the ConciseSet's set of values [0,4,9], not as a bitmap position.

Also, given this behavior, if I have a Concise-backed ImmutableBitmap and I call get() in a loop from 0 to bitmap.size(), get(0) returns false, while the range from 1 to bmp.size() - 1 returns true (0 should return true as well)

If I switch to Roaring-backed, get() works as expected, the input is treated as a bitmap position.

In RoaringBitmap, you can get the ith value by calling the 'select' method. Otherwise, we have a 'contains' which returns a boolean.

@jon-wei given that the concise implementation existed before the roaring one, how do we define what the "correct" behavior should be?

@xvrl Shouldn't the documentation settle this? Look at what the Javadoc says the function does... and make sure the function does what it says it does... or change the Javadoc so that it describes what the function does...

I think that everyone should agree with the principle of "minimal surprise"... if after reading the javadoc you are surprised by the behavior of the function, then something is wrong.

@xvrl Roaring should have the correct behavior. I think this is just a bug from my legacy Concise code.