You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by iv...@apache.org on 2026/06/04 06:55:46 UTC

(lucene) branch branch_10x updated: Use BitSet's nextClearBit method in HnswUtil (#16181)

This is an automated email from the ASF dual-hosted git repository.

iverase pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_10x by this push:
     new b42749c41ef Use BitSet's nextClearBit method in HnswUtil (#16181)
b42749c41ef is described below

commit b42749c41efa35b3bedb0f0f2deefb7940c7ddb2
Author: Ignacio Vera <iv...@apache.org>
AuthorDate: Thu Jun 4 07:54:47 2026 +0100

    Use BitSet's nextClearBit method in HnswUtil (#16181)
---
 .../java/org/apache/lucene/util/hnsw/HnswUtil.java | 30 ++--------------------
 1 file changed, 2 insertions(+), 28 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 dff842f0870..b147f97fdd7 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
@@ -110,14 +110,14 @@ public class HnswUtil {
       components.add(new Component(entryPoint, total));
     }
     if (level == 0) {
-      int nextClear = nextClearBit(connectedNodes, 0);
+      int nextClear = connectedNodes.nextClearBit(0);
       while (nextClear != NO_MORE_DOCS) {
         Component component =
             markRooted(hnsw, level, connectedNodes, notFullyConnected, maxConn, nextClear);
         assert component.size() > 0;
         components.add(component);
         total += component.size();
-        nextClear = nextClearBit(connectedNodes, component.start());
+        nextClear = connectedNodes.nextClearBit(component.start());
       }
     } else {
       HnswGraph.NodesIterator nodes = hnsw.getNodesOnLevel(level);
@@ -198,32 +198,6 @@ public class HnswUtil {
     return new Component(entryPoint, count);
   }
 
-  private static int nextClearBit(FixedBitSet bits, int index) {
-    // Does not depend on the ghost bits being clear!
-    long[] barray = bits.getBits();
-    assert index >= 0 && index < bits.length() : "index=" + index + ", numBits=" + bits.length();
-    int i = index >> 6;
-    long word = ~(barray[i] >> index); // skip all the bits to the right of index
-
-    int next = NO_MORE_DOCS;
-    if (word != 0) {
-      next = index + Long.numberOfTrailingZeros(word);
-    } else {
-      while (++i < barray.length) {
-        word = ~barray[i];
-        if (word != 0) {
-          next = (i << 6) + Long.numberOfTrailingZeros(word);
-          break;
-        }
-      }
-    }
-    if (next >= bits.length()) {
-      return NO_MORE_DOCS;
-    } else {
-      return next;
-    }
-  }
-
   /**
    * In graph theory, "connected components" are really defined only for undirected (ie
    * bidirectional) graphs. Our graphs are directed, because of pruning, but they are *mostly*