msokolov commented on code in PR #12235: URL: https://github.com/apache/lucene/pull/12235#discussion_r1179184450
########## lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java: ########## @@ -59,23 +61,72 @@ public void add(int newNode, float newScore) { node[size] = newNode; score[size] = newScore; ++size; + ++sortedNodeSize; } - /** Add a new node to the NeighborArray into a correct sort position according to its score. */ - public void insertSorted(int newNode, float newScore) { + /** Add node and score 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); } + node[size] = newNode; + score[size] = newScore; + size++; + } + + /** + * Sort the array according to scores, and return the sorted indexes of previous unsorted nodes + * (unchecked nodes) + * + * @return indexes of newly sorted (unchecked) nodes, in ascending order, or null if the array is + * already fully sorted + */ + public int[] sort() { Review Comment: LGTM. After reading I think I see what's going on. The name is deceptively simple; I wonder if it shouldn't hint that there is something tricky going on in here? Like `sortAndReturnPreviouslyUnsorted()` :) but it's fine to leave as is - the javadoc anyway explains it -- 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