jpountz commented on a change in pull request #966: LUCENE-9024 Optimize
IntroSelector to use median of medians
URL: https://github.com/apache/lucene-solr/pull/966#discussion_r338915037
##########
File path: lucene/core/src/java/org/apache/lucene/util/IntroSelector.java
##########
@@ -33,26 +32,87 @@ public final void select(int from, int to, int k) {
quickSelect(from, to, k, maxDepth);
}
- // heap sort
- // TODO: use median of median instead to have linear worst-case rather than
- // n*log(n)
- void slowSelect(int from, int to, int k) {
- new Sorter() {
+ int slowSelect(int from, int to, int k) {
+ return medianOfMediansSelect(from, to-1, k);
+ }
+
+ int medianOfMediansSelect(int from, int to, int k) {
+ int pivotIndex;
+ do {
+ if (from == to) {
Review comment:
I believe this condition can never happen when `medianOfMediansSelect` is
called from `quickSelect` since it first checks whether `to-from==1` before
delegating to `medianOfMediansSelect`? It is probably a good idea to be
defensive, but maybe leave a comment about it?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]