Use IntHashSet instead of FixedBitSet

This commit is contained in:
Viswanath Kuchibhotla 2024-11-28 07:45:04 +05:30
parent 1d0539decb
commit ea82561520
1 changed files with 4 additions and 3 deletions

View File

@ -29,6 +29,7 @@ import org.apache.lucene.index.CodecReader;
import org.apache.lucene.index.FilterLeafReader; import org.apache.lucene.index.FilterLeafReader;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.internal.hppc.IntHashSet;
import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.FixedBitSet;
/** Utilities for use in tests involving HNSW graphs */ /** Utilities for use in tests involving HNSW graphs */
@ -166,7 +167,7 @@ public class HnswUtil {
if (connectedNodes.get(entryPoint)) { if (connectedNodes.get(entryPoint)) {
return new Component(entryPoint, 0); return new Component(entryPoint, 0);
} }
FixedBitSet nodesInStack = new FixedBitSet(hnswGraph.size()); IntHashSet nodesInStack = new IntHashSet();
Deque<Integer> stack = new ArrayDeque<>(); Deque<Integer> stack = new ArrayDeque<>();
stack.push(entryPoint); stack.push(entryPoint);
int count = 0; int count = 0;
@ -182,9 +183,9 @@ public class HnswUtil {
int friendCount = 0; int friendCount = 0;
while ((friendOrd = hnswGraph.nextNeighbor()) != NO_MORE_DOCS) { while ((friendOrd = hnswGraph.nextNeighbor()) != NO_MORE_DOCS) {
++friendCount; ++friendCount;
if (connectedNodes.get(friendOrd) == false && nodesInStack.get(friendOrd) == false) { if (connectedNodes.get(friendOrd) == false && nodesInStack.contains(friendOrd) == false) {
stack.push(friendOrd); stack.push(friendOrd);
nodesInStack.set(friendOrd); nodesInStack.add(friendOrd);
} }
} }
if (friendCount < maxConn && notFullyConnected != null) { if (friendCount < maxConn && notFullyConnected != null) {