zhaih commented on code in PR #12910: URL: https://github.com/apache/lucene/pull/12910#discussion_r1424031699
########## lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java: ########## @@ -51,45 +51,61 @@ public NeighborArray(int maxSize, boolean descOrder) { */ public void addInOrder(int newNode, float newScore) { assert size == sortedNodeSize : "cannot call addInOrder after addOutOfOrder"; - if (size == node.length) { - node = ArrayUtil.grow(node); - score = ArrayUtil.growExact(score, node.length); + if (size == nodes.length) { + throw new IllegalStateException("No growth is allowed"); } if (size > 0) { - float previousScore = score[size - 1]; + float previousScore = scores[size - 1]; assert ((scoresDescOrder && (previousScore >= newScore)) || (scoresDescOrder == false && (previousScore <= newScore))) : "Nodes are added in the incorrect order! Comparing " + newScore + " to " - + Arrays.toString(ArrayUtil.copyOfSubArray(score, 0, size)); + + Arrays.toString(ArrayUtil.copyOfSubArray(scores, 0, size)); } - node[size] = newNode; - score[size] = newScore; + nodes[size] = newNode; + scores[size] = newScore; ++size; ++sortedNodeSize; } /** Add node and newScore but do not insert as sorted */ public void addOutOfOrder(int newNode, float newScore) { - if (size == node.length) { - node = ArrayUtil.grow(node); - score = ArrayUtil.growExact(score, node.length); + if (size == nodes.length) { + throw new IllegalStateException("No growth is allowed"); } - score[size] = newScore; - node[size] = newNode; + scores[size] = newScore; + nodes[size] = newNode; size++; } + /** + * In addition to {@link #addOutOfOrder(int, float)}, this function will also remove the + * least-diverse node if the node array is full after insertion + * + * @param nodeId node Id of the owner of this NeighbourArray Review Comment: Hmmm all those methods (addInOrder/addOutOfOrder) is not threadsafe actually, it's just (according to current call pattern) only this one will be called by multiple threads. Let me hint that in the javadoc. -- 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