Merge pull request #370 from amulware/improve-gethashcode

improved GetHashCode overrides of float/double Math types, closes #355
This commit is contained in:
Harry 2016-03-28 11:20:08 +02:00
commit 8fc672ad73
28 changed files with 184 additions and 35 deletions

View file

@ -12,7 +12,7 @@ namespace OpenTK
/// Defines a 2d box (rectangle). /// Defines a 2d box (rectangle).
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct Box2 public struct Box2 : IEquatable<Box2>
{ {
/// <summary> /// <summary>
/// The left boundary of the structure. /// The left boundary of the structure.
@ -190,14 +190,21 @@ namespace OpenTK
return obj is Box2 && Equals((Box2) obj); return obj is Box2 && Equals((Box2) obj);
} }
/// <summary> ///// <summary>
/// Gets the hash code for this Box2. ///// Gets the hash code for this Box2.
/// </summary> ///// </summary>
/// <returns></returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); unchecked
{
var hashCode = this.Left.GetHashCode();
hashCode = (hashCode * 397) ^ this.Right.GetHashCode();
hashCode = (hashCode * 397) ^ this.Top.GetHashCode();
hashCode = (hashCode * 397) ^ this.Bottom.GetHashCode();
return hashCode;
} }
}
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
/// <summary> /// <summary>

View file

@ -12,8 +12,9 @@ namespace OpenTK
/// Defines a 2d box (rectangle). /// Defines a 2d box (rectangle).
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct Box2d public struct Box2d : IEquatable<Box2d>
{ {
/// <summary> /// <summary>
/// The left boundary of the structure. /// The left boundary of the structure.
/// </summary> /// </summary>
@ -193,10 +194,16 @@ namespace OpenTK
/// <summary> /// <summary>
/// Gets the hash code for this Box2d. /// Gets the hash code for this Box2d.
/// </summary> /// </summary>
/// <returns></returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); unchecked
{
var hashCode = this.Left.GetHashCode();
hashCode = (hashCode * 397) ^ this.Right.GetHashCode();
hashCode = (hashCode * 397) ^ this.Top.GetHashCode();
hashCode = (hashCode * 397) ^ this.Bottom.GetHashCode();
return hashCode;
}
} }
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;

View file

@ -721,7 +721,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode(); unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
} }
#endregion #endregion

View file

@ -721,7 +721,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode(); unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
} }
#endregion #endregion

View file

@ -679,7 +679,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode(); unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
} }
#endregion #endregion

View file

@ -679,7 +679,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode(); unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
} }
#endregion #endregion

View file

@ -716,7 +716,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode(); unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
} }
#endregion #endregion

View file

@ -716,7 +716,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode(); unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
} }
#endregion #endregion

View file

@ -960,7 +960,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -951,7 +951,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -690,7 +690,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -690,7 +690,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -954,7 +954,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -954,7 +954,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -1715,7 +1715,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row3.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -1665,7 +1665,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row3.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -739,7 +739,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row3.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -739,7 +739,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row3.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -962,7 +962,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row3.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -962,7 +962,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); unchecked
{
var hashCode = this.Row0.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row1.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row2.GetHashCode();
hashCode = (hashCode * 397) ^ this.Row3.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -857,7 +857,10 @@ namespace OpenTK
/// <returns>A hash code formed from the bitwise XOR of this objects members.</returns> /// <returns>A hash code formed from the bitwise XOR of this objects members.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Xyz.GetHashCode() ^ W.GetHashCode(); unchecked
{
return (this.xyz.GetHashCode() * 397) ^ this.w.GetHashCode();
}
} }
#endregion #endregion

View file

@ -854,9 +854,13 @@ namespace OpenTK
/// Provides the hash code for this object. /// Provides the hash code for this object.
/// </summary> /// </summary>
/// <returns>A hash code formed from the bitwise XOR of this objects members.</returns> /// <returns>A hash code formed from the bitwise XOR of this objects members.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Xyz.GetHashCode() ^ W.GetHashCode(); unchecked
{
return (this.xyz.GetHashCode() * 397) ^ this.w.GetHashCode();
}
} }
#endregion #endregion

View file

@ -1137,7 +1137,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return X.GetHashCode() ^ Y.GetHashCode(); unchecked
{
return (this.X.GetHashCode() * 397) ^ this.Y.GetHashCode();
}
} }
#endregion #endregion

View file

@ -1015,7 +1015,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return X.GetHashCode() ^ Y.GetHashCode(); unchecked
{
return (this.X.GetHashCode() * 397) ^ this.Y.GetHashCode();
}
} }
#endregion #endregion

View file

@ -1629,7 +1629,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); unchecked
{
var hashCode = this.X.GetHashCode();
hashCode = (hashCode * 397) ^ this.Y.GetHashCode();
hashCode = (hashCode * 397) ^ this.Z.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -1466,7 +1466,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); unchecked
{
var hashCode = this.X.GetHashCode();
hashCode = (hashCode * 397) ^ this.Y.GetHashCode();
hashCode = (hashCode * 397) ^ this.Z.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -1657,7 +1657,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode(); unchecked
{
var hashCode = this.X.GetHashCode();
hashCode = (hashCode * 397) ^ this.Y.GetHashCode();
hashCode = (hashCode * 397) ^ this.Z.GetHashCode();
hashCode = (hashCode * 397) ^ this.W.GetHashCode();
return hashCode;
}
} }
#endregion #endregion

View file

@ -1613,7 +1613,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns> /// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode(); unchecked
{
var hashCode = this.X.GetHashCode();
hashCode = (hashCode * 397) ^ this.Y.GetHashCode();
hashCode = (hashCode * 397) ^ this.Z.GetHashCode();
hashCode = (hashCode * 397) ^ this.W.GetHashCode();
return hashCode;
}
} }
#endregion #endregion