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

Get element by index #252

Open
irevoire opened this issue Apr 24, 2023 · 2 comments
Open

Get element by index #252

irevoire opened this issue Apr 24, 2023 · 2 comments

Comments

@irevoire
Copy link
Contributor

irevoire commented Apr 24, 2023

It's not the first time that I need a function to get element(s) by index in a roaring bitmap.
The main functions that I could have used are;

  • nth(n: u32) -> u32 => returns the element at the n position
  • first_n(n: u32) -> RoaringBitmap => returns the first n elements
  • last_n(n: u32) -> RoaringBitmap => returns the last n elements
@Kerollmops
Copy link
Member

Hey 👋,

The nth method makes me think of the select one. Is it what you are looking for?

However, there could be a better way than implementing the first_n and last_n methods than using the Iterator trait. As I don't think we can simply implement some methods on the Iterator trait, maybe implementing those on the RoaringBitmap type could be enough 🤷‍♂️

@irevoire
Copy link
Contributor Author

The nth method makes me think of the select one. Is it what you are looking for?

Oops, yes, definitely, thanks!

However, there could be a better way than implementing the first_n and last_n methods than using the Iterator trait

Yeah, if n is large, we could easily skip through whole containers without opening them and without any resizing happening while allocating all the Vecs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants