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

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

    Attachment: OptimizedEquatableListOfT.patch

I've optimized the EquatableList<T> class when comparing for equality.  I've 
used a technique that is used a great deal in LINQ (but doesn't require it) 
"type sniffing" to sniff out types that could allow for shortcuts in checking 
for the equality of the list.

Namely, I've had the equality method check to see if both of the IEnumerable<T> 
implementations implement ICollection or ICollection<T> to get a count.  If 
they both can provide a count, then those are compared.  If they are different, 
there is no need to enumerate through all of the items in both lists.

For lists where N is small, it doesn't make much of a difference (it won't 
hurt), but for lists where both lists have about the same number of elements 
(but not exactly) and N is large, it will make a massive difference (not all 
items have to be enumerated).

If you want me to create a separate patch that has just the changes to 
SupportClass, then let me know and I can do that, but I think this is important 
for the implementation of EquatableList<T> given Lucene's general concern with 
performance.

> 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, EquatableListOfT.patch, 
> EquatableListOfT_tweaked.patch, OptimizedEquatableListOfT.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.

Reply via email to