Menu

#37 hashcode not equal

1.4.2.0
open-postponed
5
2009-04-01
2009-02-20
Gavin
No

I am trying to use a dictionary with an Oatc.OpenMI.Sdk.Backbone.ExchangeItem as a key.

Unfortunately if I create two exchange items (e1 and e2) with the same quanity and elements set I find the e1.Equals(e2) but e1.GetHashCode() is not equal to e2.GetHashCode(). This is due to the use of Object.GetHashCode() in ExchangeItem. It generates a unique hash code per instance.

This renders dictionaries key by exchange items useless it is exactly the same item (which can't happen because exchange items are not passed around only links, quantities and element sets).

Discussion

  • Adrian Harper

    Adrian Harper - 2009-04-01

    Yes this is an issue. I have investigated the history and this is a consequence of trying to leverage the Equals method to represent IsSameAs queries. This was a mistake and is addressed in the proposed version 2 of the standard by having a method specifically for this. This means that in version 2, there will be no overriding of the default functionality for Equals and Hash codes.

    As to version 1.4. After consideration it has been decided not to change the functionality for the 1.4.1 release as this has the potential to break other existing implementations. The work around until version2 is for people to use there own modified versions of the SDK.

     
  • Adrian Harper

    Adrian Harper - 2009-04-01
    • milestone: --> 488982
    • assigned_to: nobody --> adharper
    • status: open --> open-postponed
     
  • Adrian Harper

    Adrian Harper - 2009-04-01
    • milestone: 488982 --> 1.4.2.0
     

Log in to post a comment.