Skip to content
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

first() and last() methods like RoaringBitmap in Roaring64Bitmap #583

Open
nareshv opened this issue Sep 8, 2022 · 4 comments
Open

first() and last() methods like RoaringBitmap in Roaring64Bitmap #583

nareshv opened this issue Sep 8, 2022 · 4 comments

Comments

@nareshv
Copy link

nareshv commented Sep 8, 2022

Is your feature request related to a problem? Please describe.
RoaringBitmap provides first() and last() methods to determine the start and end values present in the bitmap. These methods are not present in the latest release. There are couple of alternatives which available are Roaring64Bitmap.toArray() and then get the first/last values in the array. There is also a Roaring64Bitmap.query(j), with query() function can we use .cardinatliy to get the first/last values in the bitmap ?

Describe the solution you'd like
Whats the most efficient way to get the first() and last() values in the bitmap without iterating over the entire dataset ?

Please note that this is a community-based project. Consider proposing a fix (code, documentation) as a pull request.

@lemire
Copy link
Member

lemire commented Sep 8, 2022

You can use getReverseLongIterator() and getLongIterator() to get the last() and first() value respectively.

@nareshv
Copy link
Author

nareshv commented Sep 8, 2022

Thanks. I was also reading the code,

                long all = bitmap.getLongCardinality();
                long start = bitmap.select(0);
                long end = bitmap.select(all - 1);

also seem to work.
In terms of performance between select() vs *Iterator whats preferred ?

@richardstartin
Copy link
Member

Select is linear in the number of bits, the reverse iterator is constant time. Specialised first and last methods would be more efficient though, if someone wants to add them.

@lemire
Copy link
Member

lemire commented Sep 8, 2022

@richardstartin is correct. The iterators are better, but we could do even better with specialized functions.

blacelle added a commit to blacelle/RoaringBitmap that referenced this issue Nov 13, 2022
lemire pushed a commit that referenced this issue Nov 14, 2022
* Introduce .first and .last to 64 implementation #583

* Restore unexpected change of char to int

* Cast low part from int to char

* step-fown the Art manually

* Improve Style, add test by refactoring source for allKindsOfNodes

* Improve behavior and tests if RB64 is empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants