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

Julian Hyde commented on CALCITE-4096:
--------------------------------------

As long as {{Pair}} implements {{Map.Entry}} we have to use {{Map.Entry}}'s 
hashCode algorithm. So in effect you are proposing to make {{Pair}} no longer 
implement {{Map.Entry}}.

For pairs where both entries have the same type, consider using 
{{FlatLists.Flat2List}}. It uses List's {{hashCode}} algorithm, {{(31 + 
left.HashCode()) * 31 + right.hashCode()}}. The space overhead is the same as 
Pair - a struct with two pointers.

> Change Pair.hashCode() not to use XOR
> -------------------------------------
>
>                 Key: CALCITE-4096
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4096
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: Haisheng Yuan
>            Priority: Major
>
> JDK Map Entry uses XOR maybe because it is unlikely to use Map Entry as the 
> HashMap key.
> But Pair in Calcite is a general data structure, it is used in several places 
> as the key of HashMap/HashSet. XOR is not a good candidate for hash 
> algorithm, it is more likely to generate hash collision than simple prime 
> multiplication, especially when pair.left equals pair.right.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to