Add an rb_group_elements_by_source function#66
Open
chriswheeldon-peakon wants to merge 1 commit intoChenHuajun:masterfrom
Open
Add an rb_group_elements_by_source function#66chriswheeldon-peakon wants to merge 1 commit intoChenHuajun:masterfrom
rb_group_elements_by_source function#66chriswheeldon-peakon wants to merge 1 commit intoChenHuajun:masterfrom
Conversation
…nt int, sources int[])
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR is a proposal for a new set returning function,
rb_group_elements_by_source(bitmaps roaringbitmap[]) → TABLE (sources int[], members roaringbitmap), that, given an array of input bitmaps returns a table, where each row contains an array of indexes into the source bitmap array and a single bitmap with the common set of elements that were contained in those source bitmaps.For example,
i.e.
For our case, we need to perform this grouping on between 10 and 200 bitmaps, each containing on the order ~100,000 elements. We've tried, therefore, to focus on finding a performant implementation and, though our use-case is likely very specific to our domain and problem space, we have tried to extract the computationally expensive part out into what we hope is a generic enough and potentially generally useful enough function to make it suitable for inclusion in this library.
I haven't yet implemented a 64-bit version, as I was hoping to get some feedback on this before proceeding with that.
Many thanks for this library and for taking the time to look over this proposal 🙇
Implementation Details
The function builds a min-heap over the input bitmaps iterators and a hashtable mapping a given combination of input array indices, represented as a bitmask, to a bitmap. It then repeatedly pops from the heap to find all the bitmaps that contain a given element (i.e. a k-way merge), updating the bitmask as it goes. When no more iterators exist that return that element we look up the bitmask in the hashtable, inserting if it does not exist, and then add the value to the corresponding bitmap. We then continue popping off the heap for the next element.