Lucene.Net.Core.Support: Deleted HashHelpers and ObjectExtensions because they have been replaced by the Collections.GetHashCode() and Collections.Equals() functionality
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/92b7d0b7 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/92b7d0b7 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/92b7d0b7 Branch: refs/heads/api-work Commit: 92b7d0b7a3b2fc021bff49dc3057fd52f12dd7be Parents: f25215f Author: Shad Storhaug <[email protected]> Authored: Thu Mar 30 09:29:51 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Mar 30 09:29:51 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Lucene.Net.csproj | 2 - src/Lucene.Net.Core/Support/HashHelpers.cs | 127 ------------------- src/Lucene.Net.Core/Support/ObjectExtensions.cs | 56 -------- 3 files changed, 185 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92b7d0b7/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 622d7b3..d140dd4 100644 --- a/src/Lucene.Net.Core/Lucene.Net.csproj +++ b/src/Lucene.Net.Core/Lucene.Net.csproj @@ -643,7 +643,6 @@ <Compile Include="Support\ExceptionToClassNameConventionAttribute.cs" /> <Compile Include="Support\ExceptionToNullableEnumConvention.cs" /> <Compile Include="Support\FileStreamExtensions.cs" /> - <Compile Include="Support\HashHelpers.cs" /> <Compile Include="Support\ICallable.cs" /> <Compile Include="Support\ICharSequence.cs" /> <Compile Include="Support\ICompletionService.cs" /> @@ -666,7 +665,6 @@ <Compile Include="Support\MathExtension.cs" /> <Compile Include="Support\MemoryMappedFileByteBuffer.cs" /> <Compile Include="Support\NumberFormat.cs" /> - <Compile Include="Support\ObjectExtensions.cs" /> <Compile Include="Support\PriorityQueue.cs" /> <Compile Include="Support\ReaderWriterLockSlimExtensions.cs" /> <Compile Include="Support\ReentrantLock.cs" /> http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92b7d0b7/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 deleted file mode 100644 index 5268a43..0000000 --- a/src/Lucene.Net.Core/Support/HashHelpers.cs +++ /dev/null @@ -1,127 +0,0 @@ -//----------------------------------------------------------------------- -// <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/92b7d0b7/src/Lucene.Net.Core/Support/ObjectExtensions.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Support/ObjectExtensions.cs b/src/Lucene.Net.Core/Support/ObjectExtensions.cs deleted file mode 100644 index 37ef70b..0000000 --- a/src/Lucene.Net.Core/Support/ObjectExtensions.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Collections; - -namespace Lucene.Net.Support -{ - public static class ObjectExtensions - { - /// <summary> - /// Compares the current value against the other value to determine if - /// the values are equal. If the values implement IEnumerable (and are - /// not strings), then it will enumerate over the values and compare them - /// in the same order. - /// - /// This differs from most SetEquals implementations in that they usually - /// don't check the order of the elements in the IEnumerable, but this one does. - /// It also does the check in a safe manner in case the IEnumerable type is nullable, - /// so that null == null. - /// - /// The values that are provided don't necessarily have to implement IEnumerable - /// to check their values for equality. - /// - /// This method is most useful for assertions and testing, but it may - /// also be useful in other scenarios. Do note the IEnumerable values are cast to - /// object before comparing, so it may not be ideal for production scenarios - /// if the values are not reference types. - /// </summary> - /// <typeparam name="T">The type of object</typeparam> - /// <param name="a">This object</param> - /// <param name="b">The object that this object will be compared against</param> - /// <returns><c>true</c> if the values are equal; otherwise <c>false</c></returns> - public static bool ValueEquals<T>(this T a, T b) - { - if (a is IEnumerable && b is IEnumerable) - { - var iter = (b as IEnumerable).GetEnumerator(); - foreach (object value in a as IEnumerable) - { - iter.MoveNext(); - if (!object.Equals(value, iter.Current)) - { - return false; - } - } - return true; - } - - return a.Equals(b); - } - - // Special case: strings are IEnumerable, but the default Equals works fine - // for testing value equality - public static bool ValueEquals(this string a, string b) - { - return a.Equals(b); - } - } -}
