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

Optimize the implementation of OrCardinality #40

Closed
lemire opened this issue Sep 29, 2015 · 8 comments
Closed

Optimize the implementation of OrCardinality #40

lemire opened this issue Sep 29, 2015 · 8 comments

Comments

@lemire
Copy link
Member

lemire commented Sep 29, 2015

Currently, the OrCardinality function materializes temporary containers that are immediately (?) garbage collected. This is wasteful. Instead, we should have fast container-to-container union functions that just return the cardinality without doing memory allocation, as is the case with the intersections.

// TODO: could be faster if we did not have to materialize the container

c.c. @tgruben @statik @bpot @tvmaly

@lemire lemire changed the title Implement set operations (does_it_intersects, or_cardinality, and_intersection...) Implement set operations (does_it_intersects, or_cardinality, and_cardinality...) Sep 29, 2015
@statik
Copy link
Member

statik commented Jun 7, 2016

@lemire I started taking a look at this and got a little confused. I'll list out what I found, and just say there is a good chance I'm missing something and would greatly appreciate any pointers on what operations are still missing here.

https://github.com/RoaringBitmap/roaring/blob/master/setutil.go#L211 has intersects2by2. Not sure if the 2by2 suffix is correct, when comparing https://github.com/RoaringBitmap/RoaringBitmap/blob/50d435c5f82df78b5d369f4120559e10c3455e95/src/main/java/org/roaringbitmap/Util.java#L680

intersects2by2 is called from

return intersects2by2(
which seems similar to the way it is used in java https://github.com/RoaringBitmap/RoaringBitmap/blob/78ad3a1c11e374e471e4fc666257569269447412/src/main/java/org/roaringbitmap/ArrayContainer.java#L573

I also see OrCardinality, AndCardinality, and Intersects implemented herev in the public API:

// OrCardinality returns the cardinality of the union between two bitmaps, bitmaps are not modified

func (rb *Bitmap) AndCardinality(x2 *Bitmap) uint64 {

func (rb *Bitmap) Intersects(x2 *Bitmap) bool {

@lemire
Copy link
Member Author

lemire commented Jun 7, 2016

@statik I'll get back to you.

@lemire
Copy link
Member Author

lemire commented Jun 7, 2016

@statik

Not sure if the 2by2 suffix is correct

It means that we take the intersection of two sets... as opposed to intersecting 3 sets, and so forth. Arguably, the 2by2 suffix is unnecessary but that's a private function.

@lemire
Copy link
Member Author

lemire commented Jun 7, 2016

@statik

Ok. So the current status of this issue is that it is all implemented except that the OrCardinality function materializes the temporary containers needlessly.

// TODO: could be faster if we did not have to materialize the container

I'll update the issue description to avoid confusion.

@lemire lemire changed the title Implement set operations (does_it_intersects, or_cardinality, and_cardinality...) Optimize the implementation of OrCardinality Jun 7, 2016
@lemire
Copy link
Member Author

lemire commented Jun 7, 2016

@statik

Done. Let us hope that things are clearer now. Thanks for the feedback.

@statik
Copy link
Member

statik commented Jun 7, 2016

@lemire thanks! this makes sense. I hope to find some time to work on this.

@lemire
Copy link
Member Author

lemire commented Jun 7, 2016

@statik Please do. And, also, if you do, don't forget to throw in extra tests for good measure!

@lemire
Copy link
Member Author

lemire commented Mar 17, 2017

Resolved as of this commit 8a91ca4

@lemire lemire closed this as completed Mar 17, 2017
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

2 participants