dcapwell commented on code in PR #264:
URL: https://github.com/apache/cassandra-accord/pull/264#discussion_r2632692763
##########
accord-core/src/main/java/accord/utils/SmallBitSet.java:
##########
@@ -40,29 +40,50 @@ 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)
Review Comment:
not safe it seems; need to keep this logic
```
40: Clear
41: setRange(0, 0)
```
```
Expected :0
Actual :64
```
--
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]