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_r338919830
 
 

 ##########
 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) {
+        return from;
+      }
+      pivotIndex = pivot(from, to);
+      setPivot(pivotIndex);
+      pivotIndex = partition(from, to, k, pivotIndex);
 
 Review comment:
   In my opinion it'd be better to move the call to setPivot to the beginning 
of the partition routine. The only purpose of `setPivot` is to be able to call 
`comparePivot` later, so I would find it better if calling both was the 
responsibility of the same method.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to