Lucene.Net.Core.Support.Arrays.GetHashCode(): Changed implementation to be more 
like the original JDK version, including the ability to build the hash code 
based on the values of the nested value if it is a collection


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/842182c3
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/842182c3
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/842182c3

Branch: refs/heads/api-work
Commit: 842182c3439c014b8b7e3248e504c754112005fb
Parents: d072fc7
Author: Shad Storhaug <[email protected]>
Authored: Thu Mar 30 09:40:29 2017 +0700
Committer: Shad Storhaug <[email protected]>
Committed: Thu Mar 30 09:40:29 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Support/Arrays.cs | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/842182c3/src/Lucene.Net.Core/Support/Arrays.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Arrays.cs 
b/src/Lucene.Net.Core/Support/Arrays.cs
index 8a83f22..80cd06e 100644
--- a/src/Lucene.Net.Core/Support/Arrays.cs
+++ b/src/Lucene.Net.Core/Support/Arrays.cs
@@ -11,14 +11,18 @@ namespace Lucene.Net.Support
             if (a == null)
                 return 0;
 
-            int hash = 17;
+            int result = 1;
+            bool isValueType = typeof(T).IsValueType;
 
             foreach (var item in a)
             {
-                hash = hash * 23 + (item == null ? 0 : item.GetHashCode());
+                result = 31 * result + (item == null ? 0 : 
+                    // LUCENENET specific: if this is a reference type, pass to
+                    // Collections.GetHashCode() in case we have an array of 
collections
+                    (isValueType ? item.GetHashCode() : 
Collections.GetHashCode(item)));
             }
 
-            return hash;
+            return result;
         }
 
         /// <summary>

Reply via email to