Browse Source

[SL.Core] Extend HashHelper.Combine to accept 2, 3, or 4 args

pull/1087/head
Jason Nelson 8 years ago
parent
commit
9f2ae5eaf9
  1. 36
      src/SixLabors.Core/Helpers/HashHelpers.cs
  2. 11
      src/SixLabors.Core/Primitives/Rectangle.cs
  3. 11
      src/SixLabors.Core/Primitives/RectangleF.cs

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

@ -13,7 +13,7 @@ namespace SixLabors
/// </summary>
/// <param name="h1">Hash code one</param>
/// <param name="h2">Hash code two</param>
/// <returns>Returns a hash code for the two specified has codes.</returns>
/// <returns>Returns a hash code for the provided hash codes.</returns>
public static int Combine(int h1, int h2)
{
unchecked
@ -24,5 +24,39 @@ namespace SixLabors
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>
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>
public static int Combine(int h1, int h2, int h3, int h4)
{
int hash = Combine(h1, h2);
hash = Combine(hash, h3);
hash = Combine(hash, h4);
return hash;
}
}
}

11
src/SixLabors.Core/Primitives/Rectangle.cs

@ -460,11 +460,12 @@ namespace SixLabors.Primitives
private int GetHashCode(Rectangle rectangle)
{
int hashCode = rectangle.X.GetHashCode();
hashCode = HashHelpers.Combine(hashCode, rectangle.Y.GetHashCode());
hashCode = HashHelpers.Combine(hashCode, rectangle.Width.GetHashCode());
hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode());
return hashCode;
return HashHelpers.Combine(
rectangle.X.GetHashCode(),
rectangle.Y.GetHashCode(),
rectangle.Width.GetHashCode(),
rectangle.Height.GetHashCode()
);
}
}
}

11
src/SixLabors.Core/Primitives/RectangleF.cs

@ -393,11 +393,12 @@ namespace SixLabors.Primitives
private int GetHashCode(RectangleF rectangle)
{
int hashCode = rectangle.X.GetHashCode();
hashCode = HashHelpers.Combine(hashCode, rectangle.Y.GetHashCode());
hashCode = HashHelpers.Combine(hashCode, rectangle.Width.GetHashCode());
hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode());
return hashCode;
return HashHelpers.Combine(
rectangle.X.GetHashCode(),
rectangle.Y.GetHashCode(),
rectangle.Width.GetHashCode(),
rectangle.Height.GetHashCode()
);
}
}
}
Loading…
Cancel
Save