danmuzi commented on code in PR #11784:
URL: https://github.com/apache/lucene/pull/11784#discussion_r978324992


##########
lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java:
##########
@@ -46,27 +45,23 @@ public NeighborArray(int maxSize, boolean descOrder) {
    * nodes.
    */
   public void add(int newNode, float newScore) {
-    if (size == node.length) {
-      node = ArrayUtil.grow(node);
-      score = ArrayUtil.growExact(score, node.length);
-    }
-    if (size > 0) {
-      float previousScore = score[size - 1];
-      assert ((scoresDescOrder && (previousScore >= newScore))
-              || (scoresDescOrder == false && (previousScore <= newScore)))
-          : "Nodes are added in the incorrect order!";
-    }
+    assert isSorted(newScore) : "Nodes are added in the incorrect order!";
     node[size] = newNode;
     score[size] = newScore;
     ++size;
   }
 
+  private boolean isSorted(float newScore) {
+    if (size > 0) {
+      float previousScore = score[size - 1];
+      return ((scoresDescOrder && (previousScore >= newScore))
+          || (scoresDescOrder == false && (previousScore <= newScore)));

Review Comment:
   It seems to be an [XNOR](https://en.wikipedia.org/wiki/XNOR_gate) operation.
   (A & B) | (!A & !B) => A == B
   So it can be changed to a simple form as follows:
   ```java
   return (previousScore == newScore) || (scoresDescOrder == (previousScore > 
newScore));
   ```



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