You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/01/31 17:55:44 UTC
[11/50] [abbrv] lucenenet git commit: Lucene.Net.Core.Support:
Renamed HashCodeMerge.cs > HashHelpers.cs to match the contained class
Lucene.Net.Core.Support: Renamed HashCodeMerge.cs > HashHelpers.cs to match the contained class
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/9a657cd9
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/9a657cd9
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/9a657cd9
Branch: refs/heads/api-work
Commit: 9a657cd915407d9d06454b9d3f1d83bdd0d09b7d
Parents: cc86c7d
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Tue Jan 31 11:40:26 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Tue Jan 31 11:40:26 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net.Core/Lucene.Net.csproj | 2 +-
src/Lucene.Net.Core/Support/HashCodeMerge.cs | 127 ----------------------
src/Lucene.Net.Core/Support/HashHelpers.cs | 127 ++++++++++++++++++++++
3 files changed, 128 insertions(+), 128 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9a657cd9/src/Lucene.Net.Core/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Lucene.Net.csproj b/src/Lucene.Net.Core/Lucene.Net.csproj
index 36b819b..ebe727c 100644
--- a/src/Lucene.Net.Core/Lucene.Net.csproj
+++ b/src/Lucene.Net.Core/Lucene.Net.csproj
@@ -628,7 +628,7 @@
<Compile Include="Support\DataOutputStream.cs" />
<Compile Include="Support\ExceptionToClassNameConventionAttribute.cs" />
<Compile Include="Support\FileStreamExtensions.cs" />
- <Compile Include="Support\HashCodeMerge.cs" />
+ <Compile Include="Support\HashHelpers.cs" />
<Compile Include="Support\ICallable.cs" />
<Compile Include="Support\ICharSequence.cs" />
<Compile Include="Support\ICompletionService.cs" />
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9a657cd9/src/Lucene.Net.Core/Support/HashCodeMerge.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/HashCodeMerge.cs b/src/Lucene.Net.Core/Support/HashCodeMerge.cs
deleted file mode 100644
index 5268a43..0000000
--- a/src/Lucene.Net.Core/Support/HashCodeMerge.cs
+++ /dev/null
@@ -1,127 +0,0 @@
-\ufeff//-----------------------------------------------------------------------
-// <copyright file="HashHelpers.cs" company="Microsoft">
-// Copyright (c) Microsoft. All rights reserved.
-// Internal use only.
-// </copyright>
-//-----------------------------------------------------------------------
-
-using System;
-using System.Collections;
-
-namespace Lucene.Net.Support
-{
- public static class HashHelpers
- {
- public static int CombineHashCodes(int h1, int h2)
- {
- return ((h1 << 5) + h1) ^ h2;
- }
-
- public static int CombineHashCodes(int h1, int h2, int h3)
- {
- return HashHelpers.CombineHashCodes(h1, HashHelpers.CombineHashCodes(h2, h3));
- }
-
- public static int CombineHashCodes(int h1, int h2, int h3, int h4)
- {
- return HashHelpers.CombineHashCodes(
- HashHelpers.CombineHashCodes(h1, h2),
- HashHelpers.CombineHashCodes(h3, h4)
- );
- }
-
- public static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5)
- {
- return HashHelpers.CombineHashCodes(
- HashHelpers.CombineHashCodes(h1, h2),
- HashHelpers.CombineHashCodes(h3, h4),
- h5
- );
- }
-
- private static uint[] crc32Table;
-
- public static int GetCRC32HashCode(this byte[] buffer, int offset, int count)
- {
- if (null == buffer)
- {
- throw new ArgumentNullException("buffer");
- }
-
- if ((offset + count) > buffer.Length)
- {
- count = (buffer.Length - offset);
- }
-
- if (null == HashHelpers.crc32Table)
- {
- uint[] localCrc32Table = new uint[256];
-
- for (uint i = 0; i < 256; i++)
- {
- uint c = i;
- for (int k = 0; k < 8; k++)
- {
- if (0 != (c & 1))
- {
- c = 0xedb88320 ^ (c >> 1);
- }
- else
- {
- c = c >> 1;
- }
- }
-
- localCrc32Table[i] = c;
- }
-
- HashHelpers.crc32Table = localCrc32Table;
- }
-
- uint crc32Value = uint.MaxValue;
- for (int i = offset, max = offset + count; i < max; i++)
- {
- byte index = (byte)(crc32Value ^ buffer[i]);
- crc32Value = HashHelpers.crc32Table[index] ^ ((crc32Value >> 8) & 0xffffff);
- }
-
- return (int)crc32Value;
- }
-
- /// <summary>
- /// Gets a hash code for the valueOrEnumerable. If the valueOrEnumerable implements
- /// IEnumerable, it enumerates the values and makes a combined hash code representing
- /// all of the values in the order they occur in the set. The types of IEnumerable must also be
- /// the same, so for example a <see cref="int[]"/> and a <see cref="List{Int32}"/> containing
- /// the same values will have different hash codes.
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="valueOrEnumerable">Any value type, reference type or IEnumerable type.</param>
- /// <returns>A combined hash code of the value and, if IEnumerable, any values it contains.</returns>
- public static int GetValueHashCode<T>(this T valueOrEnumerable)
- {
- if (valueOrEnumerable == null)
- return 0; // 0 for null
-
- if (!(valueOrEnumerable is IEnumerable) || valueOrEnumerable is string)
- {
- return valueOrEnumerable.GetHashCode();
- }
-
- int hashCode = valueOrEnumerable.GetType().GetHashCode();
- foreach (object value in valueOrEnumerable as IEnumerable)
- {
- if (value != null)
- {
- hashCode = CombineHashCodes(hashCode, value.GetHashCode());
- }
- else
- {
- hashCode = CombineHashCodes(hashCode, 0 /* 0 for null */);
- }
- }
-
- return hashCode;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9a657cd9/src/Lucene.Net.Core/Support/HashHelpers.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/HashHelpers.cs b/src/Lucene.Net.Core/Support/HashHelpers.cs
new file mode 100644
index 0000000..5268a43
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/HashHelpers.cs
@@ -0,0 +1,127 @@
+\ufeff//-----------------------------------------------------------------------
+// <copyright file="HashHelpers.cs" company="Microsoft">
+// Copyright (c) Microsoft. All rights reserved.
+// Internal use only.
+// </copyright>
+//-----------------------------------------------------------------------
+
+using System;
+using System.Collections;
+
+namespace Lucene.Net.Support
+{
+ public static class HashHelpers
+ {
+ public static int CombineHashCodes(int h1, int h2)
+ {
+ return ((h1 << 5) + h1) ^ h2;
+ }
+
+ public static int CombineHashCodes(int h1, int h2, int h3)
+ {
+ return HashHelpers.CombineHashCodes(h1, HashHelpers.CombineHashCodes(h2, h3));
+ }
+
+ public static int CombineHashCodes(int h1, int h2, int h3, int h4)
+ {
+ return HashHelpers.CombineHashCodes(
+ HashHelpers.CombineHashCodes(h1, h2),
+ HashHelpers.CombineHashCodes(h3, h4)
+ );
+ }
+
+ public static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5)
+ {
+ return HashHelpers.CombineHashCodes(
+ HashHelpers.CombineHashCodes(h1, h2),
+ HashHelpers.CombineHashCodes(h3, h4),
+ h5
+ );
+ }
+
+ private static uint[] crc32Table;
+
+ public static int GetCRC32HashCode(this byte[] buffer, int offset, int count)
+ {
+ if (null == buffer)
+ {
+ throw new ArgumentNullException("buffer");
+ }
+
+ if ((offset + count) > buffer.Length)
+ {
+ count = (buffer.Length - offset);
+ }
+
+ if (null == HashHelpers.crc32Table)
+ {
+ uint[] localCrc32Table = new uint[256];
+
+ for (uint i = 0; i < 256; i++)
+ {
+ uint c = i;
+ for (int k = 0; k < 8; k++)
+ {
+ if (0 != (c & 1))
+ {
+ c = 0xedb88320 ^ (c >> 1);
+ }
+ else
+ {
+ c = c >> 1;
+ }
+ }
+
+ localCrc32Table[i] = c;
+ }
+
+ HashHelpers.crc32Table = localCrc32Table;
+ }
+
+ uint crc32Value = uint.MaxValue;
+ for (int i = offset, max = offset + count; i < max; i++)
+ {
+ byte index = (byte)(crc32Value ^ buffer[i]);
+ crc32Value = HashHelpers.crc32Table[index] ^ ((crc32Value >> 8) & 0xffffff);
+ }
+
+ return (int)crc32Value;
+ }
+
+ /// <summary>
+ /// Gets a hash code for the valueOrEnumerable. If the valueOrEnumerable implements
+ /// IEnumerable, it enumerates the values and makes a combined hash code representing
+ /// all of the values in the order they occur in the set. The types of IEnumerable must also be
+ /// the same, so for example a <see cref="int[]"/> and a <see cref="List{Int32}"/> containing
+ /// the same values will have different hash codes.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="valueOrEnumerable">Any value type, reference type or IEnumerable type.</param>
+ /// <returns>A combined hash code of the value and, if IEnumerable, any values it contains.</returns>
+ public static int GetValueHashCode<T>(this T valueOrEnumerable)
+ {
+ if (valueOrEnumerable == null)
+ return 0; // 0 for null
+
+ if (!(valueOrEnumerable is IEnumerable) || valueOrEnumerable is string)
+ {
+ return valueOrEnumerable.GetHashCode();
+ }
+
+ int hashCode = valueOrEnumerable.GetType().GetHashCode();
+ foreach (object value in valueOrEnumerable as IEnumerable)
+ {
+ if (value != null)
+ {
+ hashCode = CombineHashCodes(hashCode, value.GetHashCode());
+ }
+ else
+ {
+ hashCode = CombineHashCodes(hashCode, 0 /* 0 for null */);
+ }
+ }
+
+ return hashCode;
+ }
+ }
+}
\ No newline at end of file