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


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/RangeSet.java:
##########
@@ -163,6 +171,7 @@ public boolean equals(Object o) {
         if (!(o instanceof Set<?> otherSet)) return false;
 
         if (o instanceof RangeSet other) {
+            if (this.size() == 0 && other.size() == 0) return true;

Review Comment:
   If there is no `to < from`, probably we can remove this condition.



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/RangeSet.java:
##########
@@ -176,8 +185,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 = size();
+        if (size <= 0) return 0;

Review Comment:
   ditto



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