roaring-rs
roaring-rs copied to clipboard
Get element by index
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 thenpositionfirst_n(n: u32) -> RoaringBitmap=> returns the firstnelementslast_n(n: u32) -> RoaringBitmap=> returns the lastnelements
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 🤷♂️
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.