chia7712 commented on code in PR #19678:
URL: https://github.com/apache/kafka/pull/19678#discussion_r2084578468


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/RangeSet.java:
##########
@@ -44,6 +44,7 @@ public RangeSet(int from, int to) {
 
     @Override
     public int size() {
+        if (to < from) return 0;
         return to - from;

Review Comment:
   how about `return Math.max(0, to - from);`? it is more readable to me :)



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/RangeSet.java:
##########
@@ -44,6 +44,7 @@ public RangeSet(int from, int to) {
 
     @Override
     public int size() {
+        if (to < from) return 0;
         return to - from;

Review Comment:
   for another, is `to < from` valid? If not, maybe we should throw exception 
in constructor?



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/RangeSet.java:
##########
@@ -176,8 +178,18 @@ public boolean equals(Object o) {
 
     @Override
     public int hashCode() {
-        int result = from;
-        result = 31 * result + to;
-        return result;
+        // The hash code of a Set is defined as the sum of the hash codes of 
its elements.
+        // The hash code of an integer is the integer itself.
+
+        // The sum of the integers from 1 to n is n * (n + 1) / 2.
+        // To get the sum of the integers from 1 + k to n + k, we can add n * 
k.
+        // So our hash code comes out to n * (from + to - 1) / 2.
+        long size = (long) to - (long) from;

Review Comment:
   ```
   long size = size();
   ```



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to