iamaleksey commented on code in PR #2073:
URL: https://github.com/apache/cassandra/pull/2073#discussion_r1072332558


##########
src/java/org/apache/cassandra/dht/AccordBytesSplitter.java:
##########
@@ -20,51 +20,80 @@
 
 import java.math.BigInteger;
 
+import accord.api.RoutingKey;
+import accord.primitives.Ranges;
 import accord.utils.Invariants;
+import org.apache.cassandra.service.accord.api.AccordRoutingKey;
 
-public abstract class AccordBytesSplitter extends AccordSplitter
+import static accord.utils.Invariants.checkArgument;
+import static java.math.BigInteger.ONE;
+import static java.math.BigInteger.ZERO;
+
+public class AccordBytesSplitter extends AccordSplitter
 {
+    final int byteLength;
+
+    protected AccordBytesSplitter(Ranges ranges)
+    {
+        int bytesLength = 0;
+        for (accord.primitives.Range range : ranges)
+        {
+            bytesLength = Integer.max(bytesLength, byteLength(range.start()));
+            bytesLength = Integer.max(bytesLength, byteLength(range.end()));
+        }
+        this.byteLength = bytesLength;
+    }
+
     @Override
     BigInteger minimumValue()
     {
-        return BigInteger.ZERO;
+        return ZERO;
     }
 
     @Override
-    BigInteger maximumValue(BigInteger start)
+    BigInteger maximumValue()
     {
-        return BigInteger.ONE.shiftLeft(8 * ((start.bitLength() + 7) / 8));
+        return ONE.shiftLeft(8 * byteLength).subtract(ONE);
     }
 
     @Override
     BigInteger valueForToken(Token token)
     {
         byte[] bytes = ((ByteOrderedPartitioner.BytesToken) token).token;
-        int byteLength = 8;
-        BigInteger value = BigInteger.ZERO;
-        for (int i = 0 ; i < Math.min(8, bytes.length) ; ++i)
+        checkArgument(bytes.length <= byteLength);
+        int byteLength = byteLength(token);

Review Comment:
   This is just `bytes.length` with some extra indirection?



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