maedhroz commented on code in PR #2943:
URL: https://github.com/apache/cassandra/pull/2943#discussion_r1409985800


##########
src/java/org/apache/cassandra/index/sai/disk/v1/keystore/KeyLookup.java:
##########
@@ -265,42 +258,39 @@ public void reset() throws IOException
             readCurrentKey();
         }
 
-
         @Override
         public void close()
         {
             keysInput.close();
         }
 
-        private void updateCurrentBlockIndex(long pointId)
+        private int keyInBlockComparison(long pointId, BytesRef key)
         {
-            currentBlockIndex = pointId >>> blockShift;
-        }
+            updateCurrentBlockIndex(pointId);
+            resetToCurrentBlock();
+            if (compareKeys(key, currentKey) < 0)
+                return -1;
 
-        private boolean notInCurrentBlock(long pointId, BytesRef key)
-        {
-            if (inLastBlock(pointId))
-                return false;
+            if (currentBlockIndex == blockOffsets.length() -1)
+                return 0;
 
-            // Load the starting value of the next block into nextBlockKey.
-            long blockIndex = (pointId >>> blockShift) + 1;
             long currentFp = keysInput.getFilePointer();
-            keysInput.seek(blockOffsets.get(blockIndex) + keysFilePointer);
-            readKey(blockIndex << blockShift, nextBlockKey);
+            keysInput.seek(blockOffsets.get(currentBlockIndex + 1) + 
keysFilePointer);
+            readKey((currentBlockIndex + 1) << blockShift, nextBlockKey);
             keysInput.seek(currentFp);
-
-            return compareKeys(key, nextBlockKey) >= 0;
+            return compareKeys(key, nextBlockKey) < 0 ? 0 : 1;

Review Comment:
   ...and as for the rest of the method, we just look at the first key of the 
next block, returning 0 if the search key is less (so we're in the current 
block) and 1 otherwise (as we're in some later block).



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to