You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/09/23 07:17:03 UTC

[GitHub] [lucene] danmuzi commented on a diff in pull request #11784: NeighborArray is now fixed size

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-unsubscribe@lucene.apache.org

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


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