gsmiller commented on code in PR #14070:
URL: https://github.com/apache/lucene/pull/14070#discussion_r1904502387


##########
lucene/core/src/java/org/apache/lucene/search/DisiPriorityQueueN.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.search;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+final class DisiPriorityQueueN extends DisiPriorityQueue {
+
+  static int leftNode(int node) {
+    return ((node + 1) << 1) - 1;
+  }
+
+  static int rightNode(int leftNode) {
+    return leftNode + 1;
+  }
+
+  static int parentNode(int node) {
+    return ((node + 1) >>> 1) - 1;
+  }
+
+  private final DisiWrapper[] heap;
+  private int size;
+
+  DisiPriorityQueueN(int maxSize) {
+    heap = new DisiWrapper[maxSize];
+    size = 0;
+  }
+
+  @Override
+  public int size() {
+    return size;
+  }
+
+  @Override
+  public DisiWrapper top() {
+    return heap[0];
+  }
+
+  @Override
+  public DisiWrapper top2() {
+    switch (size()) {
+      case 0:
+      case 1:
+        return null;
+      case 2:
+        return heap[1];
+      default:
+        if (heap[1].doc <= heap[2].doc) {
+          return heap[1];
+        } else {
+          return heap[2];
+        }
+    }
+  }
+
+  @Override
+  public DisiWrapper topList() {
+    final DisiWrapper[] heap = this.heap;
+    final int size = this.size;
+    DisiWrapper list = heap[0];
+    list.next = null;
+    if (size >= 3) {
+      list = topList(list, heap, size, 1);
+      list = topList(list, heap, size, 2);
+    } else if (size == 2 && heap[1].doc == list.doc) {
+      list = prepend(heap[1], list);
+    }
+    return list;
+  }
+
+  // prepend w1 (iterator) to w2 (list)
+  private DisiWrapper prepend(DisiWrapper w1, DisiWrapper w2) {
+    w1.next = w2;
+    return w1;
+  }
+
+  private DisiWrapper topList(DisiWrapper list, DisiWrapper[] heap, int size, 
int i) {
+    final DisiWrapper w = heap[i];
+    if (w.doc == list.doc) {
+      list = prepend(w, list);
+      final int left = leftNode(i);
+      final int right = left + 1;

Review Comment:
   nit: should we use `rightNode(left)` since we have it defined?



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