[ 
https://issues.apache.org/jira/browse/LANG-1464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16862142#comment-16862142
 ] 

Florian Schmaus commented on LANG-1464:
---------------------------------------

 

> I think the Pair.hashCode need to write more complex.

Pair.hashCode() follows the API contract of Map.Entry.hashCode() which means 
the way the hash is calculated can not be changed, unless Pair does no longer 
implement Map.Entry.

That said, I think you found a weakness, if not even a bug, in the API contract 
of Map.Entry.hashCode(), which states that
{quote}The hash code f a map entry e is defined to be:
{{(e.getKey()==null ? 0 : e.getKey().hashCode()) ^ }}{{(e.getValue()==null ? 0 
: e.getValue().hashCode())}}{quote}
but this does not take the position of the Map.Entry/Pair value into account, 
and thus exhibits the pathological behavior of your test case. I wonder if 
there is an JDK issue for that.

> Hash Collision on Pair<> with auto-boxing type.
> -----------------------------------------------
>
>                 Key: LANG-1464
>                 URL: https://issues.apache.org/jira/browse/LANG-1464
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.tuple.*
>            Reporter: Shiang-Yun
>            Priority: Minor
>              Labels: performance
>
> I create 1 million objects with Integer pair. But, the total number of the 
> pair hash kinds is 1024.
> {code:java}
>     public static void main(String[] args) {
>         Set<Integer> set = new TreeSet<>();
>         for (int i = 0; i < 1000; i++) {
>             for (int j = 0; j < 1000; j++) {
>                 Pair<Integer, Integer> intPair = Pair.of(i, j);
>                 set.add(intPair.hashCode());
>             }
>         }
>         System.out.printf("%d", set.size());
>     }
> {code}
> I think the Pair.hashCode need to write more complex. 
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to