From ea825615206e11bd8f5c8edb22263111a9b87b7b Mon Sep 17 00:00:00 2001 From: Viswanath Kuchibhotla Date: Thu, 28 Nov 2024 07:45:04 +0530 Subject: [PATCH] Use IntHashSet instead of FixedBitSet --- .../src/java/org/apache/lucene/util/hnsw/HnswUtil.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswUtil.java b/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswUtil.java index 10aee15c205..313301e1345 100644 --- a/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswUtil.java +++ b/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswUtil.java @@ -29,6 +29,7 @@ import org.apache.lucene.index.CodecReader; import org.apache.lucene.index.FilterLeafReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.internal.hppc.IntHashSet; import org.apache.lucene.util.FixedBitSet; /** Utilities for use in tests involving HNSW graphs */ @@ -166,7 +167,7 @@ public class HnswUtil { if (connectedNodes.get(entryPoint)) { return new Component(entryPoint, 0); } - FixedBitSet nodesInStack = new FixedBitSet(hnswGraph.size()); + IntHashSet nodesInStack = new IntHashSet(); Deque stack = new ArrayDeque<>(); stack.push(entryPoint); int count = 0; @@ -182,9 +183,9 @@ public class HnswUtil { int friendCount = 0; while ((friendOrd = hnswGraph.nextNeighbor()) != NO_MORE_DOCS) { ++friendCount; - if (connectedNodes.get(friendOrd) == false && nodesInStack.get(friendOrd) == false) { + if (connectedNodes.get(friendOrd) == false && nodesInStack.contains(friendOrd) == false) { stack.push(friendOrd); - nodesInStack.set(friendOrd); + nodesInStack.add(friendOrd); } } if (friendCount < maxConn && notFullyConnected != null) {