Browse Source

[SL.Core] Remove HashHelpers

af/octree-no-pixelmap
Jason Nelson 7 years ago
parent
commit
73ca495916
  1. 67
      src/SixLabors.Core/Helpers/HashHelpers.cs
  2. 28
      tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs

67
src/SixLabors.Core/Helpers/HashHelpers.cs

@ -1,67 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
namespace SixLabors
{
/// <summary>
/// Provides a set of helpers for combining object hashes.
/// </summary>
internal static class HashHelpers
{
/// <summary>
/// Combines the two specified hash codes.
/// </summary>
/// <param name="h1">Hash code one</param>
/// <param name="h2">Hash code two</param>
/// <returns>Returns a hash code for the provided hash codes.</returns>
[Obsolete("Use HashCode.Combine instead")]
public static int Combine(int h1, int h2)
{
// Lifted from coreFX repo
unchecked
{
// RyuJIT optimizes this to use the ROL instruction
// Related GitHub pull request: dotnet/coreclr#1830
uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27);
return ((int)rol5 + h1) ^ h2;
}
}
/// <summary>
/// Combines the three specified hash codes.
/// </summary>
/// <param name="h1">The first </param>
/// <param name="h2">Hash code two</param>
/// <param name="h3">Hash code three</param>
/// <returns>Returns a hash code for the provided hash codes.</returns>
[Obsolete("Use HashCode.Combine instead")]
public static int Combine(int h1, int h2, int h3)
{
int hash = Combine(h1, h2);
hash = Combine(hash, h3);
return hash;
}
/// <summary>
/// Combines the four specified hash codes.
/// </summary>
/// <param name="h1">The first </param>
/// <param name="h2">Hash code two</param>
/// <param name="h3">Hash code three</param>
/// <param name="h4">Hash code four</param>
/// <returns>Returns a hash code for the provided hash codes.</returns>
[Obsolete("Use HashCode.Combine instead")]
public static int Combine(int h1, int h2, int h3, int h4)
{
int hash = Combine(h1, h2);
hash = Combine(hash, h3);
return Combine(hash, h4);
}
}
}

28
tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs

@ -1,28 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using Xunit;
namespace SixLabors.Tests.Helpers
{
public class HashHelpersTests
{
[Fact]
public void CanCombineTwoValues()
{
Assert.Equal(35, HashHelpers.Combine(1, 2));
}
[Fact]
public void CanCombineThreeValues()
{
Assert.Equal(1152, HashHelpers.Combine(1, 2, 3));
}
[Fact]
public void CanCombineFourValues()
{
Assert.Equal(38020, HashHelpers.Combine(1, 2, 3, 4));
}
}
}
Loading…
Cancel
Save