dcapwell commented on code in PR #264:
URL: https://github.com/apache/cassandra-accord/pull/264#discussion_r2620248016


##########
accord-core/src/main/java/accord/utils/SmallBitSet.java:
##########
@@ -40,29 +40,51 @@ public long bits()
         return bits;
     }
 
+    private static long bitSafe(int i)
+    {
+        validateIndex(i);
+        return bit(i);
+    }
+
+    private static void validateIndex(int i)
+    {
+        if (i >= 64 || i < 0)
+            throw new IndexOutOfBoundsException("Unable to access bit " + i + 
"; must be between 0 and 63");
+    }
+
+    @Override
     public boolean set(int i)
     {
-        long bit = bit(i);
+        long bit = bitSafe(i);
         boolean result = 0 == (bits & bit);
         bits |= bit;
         return result;
     }
 
     @Override
-    public void setRange(int from, int to)
+    public void setRange(int fromInclusive, int toExclusive)
     {
-        bits |= ~(-1L << to) & (-1L << from);
+        validateIndex(fromInclusive);
+        Invariants.requireArgument(fromInclusive <= toExclusive, "from > to 
(%s > %s)", fromInclusive, toExclusive);
+        if (fromInclusive == toExclusive)
+            return;
+
+        long maskTo = (toExclusive >= 64) ? -1L : ~(-1L << toExclusive);
+        bits |= maskTo & (-1L << fromInclusive);

Review Comment:
   in slack benedict recommend we use the logic from large: `|= (-1L >>> (64 - 
(to & 63))) & (-1L << (from & 63))`
   
   Need to test this out



-- 
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