stefanvodita commented on code in PR #12966:
URL: https://github.com/apache/lucene/pull/12966#discussion_r1552265766


##########
lucene/facet/src/java/org/apache/lucene/facet/TopOrdAndIntQueue.java:
##########
@@ -16,37 +16,42 @@
  */
 package org.apache.lucene.facet;
 
-import org.apache.lucene.util.PriorityQueue;
+/** Keeps highest results, first by largest int value, then tie-break by 
smallest ord. */
+public class TopOrdAndIntQueue extends TopOrdAndNumberQueue {
 
-/** Keeps highest results, first by largest int value, then tie break by 
smallest ord. */
-public class TopOrdAndIntQueue extends 
PriorityQueue<TopOrdAndIntQueue.OrdAndValue> {
-
-  /** Holds a single entry. */
-  public static final class OrdAndValue {
-
-    /** Ordinal of the entry. */
-    public int ord;
+  /** Sole constructor. */
+  public TopOrdAndIntQueue(int topN) {
+    super(topN);
+  }
 
-    /** Value associated with the ordinal. */
+  /** Holds an ordinal and an int value. */
+  public static final class OrdAndInt extends OrdAndValue {
+    /** The value corresponding to the ordinal is an int. */
     public int value;
 
     /** Default constructor. */
-    public OrdAndValue() {}
-  }
+    public OrdAndInt() {}
+
+    @Override
+    public boolean lessThan(OrdAndValue other) {
+      OrdAndInt otherOrdAndInt = (OrdAndInt) other;
+      if (value < otherOrdAndInt.value) {

Review Comment:
   This is how `Integer.compare` is implemented:
   ```java
        public static int compare(int x, int y) {
           return (x < y) ? -1 : ((x == y) ? 0 : 1);
        }
   ```
   And `lessThan` would become:
   ```java
       public boolean lessThan(OrdAndValue other) {
         OrdAndInt otherOrdAndInt = (OrdAndInt) other;
         int cmp = Integer.compare(value, otherOrdAndInt.value);
         if (cmp == 0) {
           cmp = Integer.compare(otherOrdAndInt.value, ord);
         }
         return cmp < 0;
       }
   ```
   I think we end up doing more comparisons overall? I might be missing 
something though.



-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to