-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement method to bulk add all collection elements to a PriorityQueue #770
Implement method to bulk add all collection elements to a PriorityQueue #770
Conversation
Maybe add a method called addAll(Collection) which would be smart enough to detect when it can use this accelerated addition instead of element-by-element addition? I'm not sure an additional constructor is needed here. |
Good point with It's always possible to build a heap if elements are provided and comparable - in JDK they check what kind of collection is provided and take comparator from it - but here we have I added a constructor as other option would be to use existing ones and then do smth like Would it it be fine if I keep the constructor but adjust it to copy directly from |
In all honesty, this is probably not something you can ever, ever notice when you compare the cost of building the heap with clearing a chunk of memory. And it makes the API simpler in my opinion. But sure, you can keep the constructor. |
2c744a6
to
815e2ee
Compare
Fair point, I changed it to |
815e2ee
to
47a2c13
Compare
73abca1
to
be0ca3e
Compare
ba1f019
to
d3d7d5b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you! Let's wait for checks to pass. Please add CHANGES.txt entry under the corresponding version (main or 9x, if you'd like this backported).
lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java
Outdated
Show resolved
Hide resolved
b8ad734
to
ae2caca
Compare
ae2caca
to
f390314
Compare
… from IllegalArgumentException to ArrayIndexOutOfBoundsException for consistency with add().
I've added a proper issue number (https://issues.apache.org/jira/browse/LUCENE-10494) and tweaked minor details of the implementation (exception types thrown in addAll and add were different). I think it's good to go. |
Thank you! |
…ue (#770) Implement method to add all collection elements to a PriorityQueue Co-authored-by: Dawid Weiss <dawid.weiss@carrotsearch.com>
Thanks! |
* main: LUCENE-10456: Implement Weight#count for MultiRangeQuery (apache#731) LUCENE-10484: Move CHANGES entry to 9.2. LUCENE-10484: Add support for concurrent facets random sampling (apache#765) LUCENE-10002: Replaces usages of FacetsCollector with FacetsCollectorManager (apache#764) LUCENE-10466: Move changelog entry to 9.2 LUCENE-10466: Ensure IndexSortSortedNumericDocValuesRangeQuery handles sort types besides LONG LUCENE-10498: don't count num hits nor accumulate scores unless necessary (apache#782) LUCENE-10184: mention of opening a Jira issue (apache#781) Update link to contribution guide Remove redundant index (apache#776) Implement method to bulk add all collection elements to a PriorityQueue (apache#770) LUCENE-10491: Fix correctness bug in TaxonomyFacetSumValueSource score providing (apache#775) Replace usages of search(Query, Collector) in CheckHits (apache#763) LUCENE-10002: Add FixedBitSetCollector and corresponding collector manager to test framework (apache#766) LUCENE-10475: Merge o.a.l.a.[ja|ko].util into o.a.l.a.[ja|ko].dict (apache#772) LUCENE-10184: add CONTRIBUTING.md; reorganize README. (apache#771) Add CHANGES entry for LUCENE-10325 LUCENE-10325: Add getTopDims functionality to Facets (apache#747)
Hi!
This PR doesn't have a link to a Jira Issue as according to contribution guidelines I can either create a patch and attach it to an issue on Jira or open a pull request - let me know if I misunderstood things and have to create a Jira issue anyway.
Description
PriorityQueue
class doesn't have a constructor accepting array/collection and I created one for the cases, when heap elements are known in advance to save some time on queue creation:O(N)
(heapify) vsNlog(N)
(calling add() in loop).Solution
JDK
PriorityQueue
has a constructor, accepting Collection and it internally usesheapify
- this PR is basically adaptation of this method (index is not 0 but 1 based and no need to check comparator presence).Tests
I added a test creating a queue filled by random elements with the new method and checking its validity. Also added a potential usage (just took randomly first usage of
add
) and it didn't cause any failures.Tried to run benchmarks using https://github.com/mikemccand/luceneutil but
got an error
may I ask is there any detailed guide on running Lucene benchmarks?
Checklist
Please review the following and check all that apply:
main
branch../gradlew check
.