lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicholas Paldino (JIRA)" <j...@apache.org>
Subject [jira] Updated: (LUCENENET-284) java vs .Net GetHashCode and Equals for ArrayList
Date Thu, 19 Nov 2009 08:49:40 GMT

     [ https://issues.apache.org/jira/browse/LUCENENET-284?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Nicholas Paldino updated LUCENENET-284:
---------------------------------------

    Attachment: ComparableListOfT.patch

I've gone over the items I've outlined above, and created a new class in SupportClass named
ComparableList<T>.

This implements IComparable<IEnumerable<T>>, IComparable, as well as IEquatable<T>,
along with the proper operator overloads to compare a sequence of this type against any IEnumerable<T>
implementation.

It will also generate the hash code based on the contents of the list.  The one place this
differs is that the hash code is primed with the hash code of the type of the type parameter
T.  The reason for this is that a ComparableList<int> and a ComparableList<string>,
both with zero elements will have the same hash code.  If you are storing a lot of empty ComparableList
instances with different type parameters in something that uses a hashcode (say, in a Hashtable),
then you will have a lot of hash conflicts, which is a bad idea.

I've also used the Comparer<T> class to perform comparisons, as it will handle implementations
of IComparable and the like on T.

The patch also includes the files that would be impacted by this, with the ArrayList swapped
out for the ComparableList<T>, which causes less code diffs.

> java vs .Net GetHashCode and Equals for ArrayList 
> --------------------------------------------------
>
>                 Key: LUCENENET-284
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-284
>             Project: Lucene.Net
>          Issue Type: Bug
>            Reporter: Andrei Iliev
>         Attachments: ArrayList.patch, ComparableListOfT.patch
>
>
> 1)In java the hash code of a list (and ArrayList) is defined to be the result of the
following calc:
> <code>
> hashCode = 1;
>   Iterator i = list.iterator();
>   while (i.hasNext()) {
>       Object obj = i.next();
>       hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
>   }
> </code>
> In .Net it hash code of object itself.
>  
> 2) In java two lists are defined to be equal if they contain the same elements in the
same order. 
> In .Net it compares the object references.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message