Skip to content

Commit

Permalink
[All] Updated code to use System.HashCode.Combine instead of Generate…
Browse files Browse the repository at this point in the history
…Hash.
  • Loading branch information
Tape-Worm committed Mar 10, 2022
1 parent 50bd2fb commit 4fec7cc
Show file tree
Hide file tree
Showing 35 changed files with 81 additions and 149 deletions.
2 changes: 1 addition & 1 deletion Gorgon/Gorgon.Core/GorgonNamedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class GorgonNamedObject
/// Returns a hash code for this instance.
/// </summary>
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
public override int GetHashCode() => string.IsNullOrWhiteSpace(Name) ? 0 : 281.GenerateHash(Name);
public override int GetHashCode() => HashCode.Combine(Name);

/// <summary>
/// Returns a <see cref="string"/> that represents the current <see cref="GorgonNamedObject"/>.
Expand Down
2 changes: 1 addition & 1 deletion Gorgon/Gorgon.Core/GorgonResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public string Name
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
public override int GetHashCode() => 281.GenerateHash(Code.GenerateHash(Name));
public override int GetHashCode() => HashCode.Combine(Code, Name);
#endregion

#region Operators.
Expand Down
8 changes: 2 additions & 6 deletions Gorgon/Gorgon.Core/Graphics/GorgonBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//
#endregion

using System;
using Gorgon.Core;
using Gorgon.Math;
using Gorgon.Properties;
Expand Down Expand Up @@ -253,12 +254,7 @@ public static bool Equals(in GorgonBox left, in GorgonBox right) => ((left.X ==
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => 281.GenerateHash(Back)
.GenerateHash(Right)
.GenerateHash(Bottom)
.GenerateHash(Left)
.GenerateHash(Top)
.GenerateHash(Front);
public override int GetHashCode() => HashCode.Combine(Back, Right, Bottom, Left, Top, Front);

/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
Expand Down
2 changes: 1 addition & 1 deletion Gorgon/Gorgon.Core/Graphics/GorgonColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public static GorgonColor FromRGBA(int rgbaColor)
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => 281.GenerateHash(Red).GenerateHash(Green).GenerateHash(Blue).GenerateHash(Alpha);
public override int GetHashCode() => HashCode.Combine(Red, Green, Blue, Alpha);

/// <summary>
/// Returns a <see cref="string"/> that represents this instance.
Expand Down
12 changes: 3 additions & 9 deletions Gorgon/Gorgon.Core/Graphics/Renderers/GorgonIntersections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,7 @@ public static bool RayIntersectsBox(in GorgonRay ray, in GorgonBoundingBox box,

if (t1 > t2)
{
float temp = t1;
t1 = t2;
t2 = temp;
(t2, t1) = (t1, t2);
}

distance = t1.Max(distance);
Expand Down Expand Up @@ -881,9 +879,7 @@ public static bool RayIntersectsBox(in GorgonRay ray, in GorgonBoundingBox box,

if (t1 > t2)
{
float temp = t1;
t1 = t2;
t2 = temp;
(t2, t1) = (t1, t2);
}

distance = t1.Max(distance);
Expand Down Expand Up @@ -912,9 +908,7 @@ public static bool RayIntersectsBox(in GorgonRay ray, in GorgonBoundingBox box,

if (t1 > t2)
{
float temp = t1;
t1 = t2;
t2 = temp;
(t2, t1) = (t1, t2);
}

distance = t1.Max(distance);
Expand Down
3 changes: 2 additions & 1 deletion Gorgon/Gorgon.Core/IO/GorgonChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//
#endregion

using System;
using Gorgon.Core;
using Gorgon.Properties;

Expand Down Expand Up @@ -69,7 +70,7 @@ namespace Gorgon.IO
/// Returns a hash code for this instance.
/// </summary>
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
public override int GetHashCode() => 281.GenerateHash(ID);
public override int GetHashCode() => HashCode.Combine(ID);

/// <summary>
/// Function to compare two instances for equality.
Expand Down
2 changes: 1 addition & 1 deletion Gorgon/Gorgon.Core/IO/GorgonFileExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public string FullExtension
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => 281.GenerateHash(Extension.ToUpperInvariant());
public override int GetHashCode() => HashCode.Combine(Extension.ToUpperInvariant());

/// <summary>
/// Returns a <see cref="string" /> that represents this instance.
Expand Down
2 changes: 1 addition & 1 deletion Gorgon/Gorgon.Core/Math/GorgonRationalNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace Gorgon.Math
/// A hash code for the current object.
/// </returns>
/// <filterpriority>2</filterpriority>
public override int GetHashCode() => 281.GenerateHash(Numerator).GenerateHash(Denominator);
public override int GetHashCode() => HashCode.Combine(Numerator, Denominator);

/// <summary>
/// Determines whether the specified object is equal to the current object.
Expand Down
24 changes: 6 additions & 18 deletions Gorgon/Gorgon.Core/Math/_Extensions/GorgonMathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,9 +1128,7 @@ public static float LimitAngle(this float angle, float min = 0, float max = 360)

if (min > max)
{
float temp = max;
max = min;
min = temp;
(min, max) = (max, min);
}

if (angle > max)
Expand Down Expand Up @@ -1162,9 +1160,7 @@ public static double LimitAngle(this double angle, double min = 0, double max =

if (min > max)
{
double temp = max;
max = min;
min = temp;
(min, max) = (max, min);
}

if (angle > max)
Expand Down Expand Up @@ -1196,9 +1192,7 @@ public static decimal LimitAngle(this decimal angle, decimal min = 0, decimal ma

if (min > max)
{
decimal temp = max;
max = min;
min = temp;
(min, max) = (max, min);
}

if (angle > max)
Expand Down Expand Up @@ -1230,9 +1224,7 @@ public static short LimitAngle(this short angle, short min = 0, short max = 360)

if (min > max)
{
short temp = max;
max = min;
min = temp;
(min, max) = (max, min);
}

if (angle > max)
Expand Down Expand Up @@ -1264,9 +1256,7 @@ public static int LimitAngle(this int angle, int min = 0, int max = 360)

if (min > max)
{
int temp = max;
max = min;
min = temp;
(min, max) = (max, min);
}


Expand Down Expand Up @@ -1299,9 +1289,7 @@ public static long LimitAngle(this long angle, long min = 0, long max = 360)

if (min > max)
{
long temp = max;
max = min;
min = temp;
(min, max) = (max, min);
}

if (angle > max)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#endregion


using System;

namespace Gorgon.Core
{
/// <summary>
Expand Down Expand Up @@ -56,6 +58,7 @@ public static class GorgonHashGenerationExtension
/// </code>
/// </para>
/// </remarks>
[Obsolete("Use System.HashCode.Combine instead.")]
public static int GenerateHash<T>(this int previousHash, T item)
{
unchecked
Expand Down
12 changes: 1 addition & 11 deletions Gorgon/Gorgon.FileSystem/GorgonFileSystemMountPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,7 @@ public static bool Equals(in GorgonFileSystemMountPoint left, in GorgonFileSyste
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
#pragma warning disable IDE0046 // Convert to conditional expression
if ((Provider is null) || (PhysicalPath is null) || (MountLocation is null))
{
return 0;
}

return 281.GenerateHash(Provider).GenerateHash(PhysicalPath).GenerateHash(MountLocation);
#pragma warning restore IDE0046 // Convert to conditional expression
}
public override int GetHashCode() => HashCode.Combine(Provider, PhysicalPath, MountLocation);

/// <summary>
/// Equality operator.
Expand Down
15 changes: 0 additions & 15 deletions Gorgon/Gorgon.Graphics.Core/Buffers/GorgonConstantBufferView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,21 +352,6 @@ public static GorgonConstantBufferView CreateConstantBuffer<T>(GorgonGraphics gr
/// <param name="other">An object to compare with this object.</param>
/// <returns><see langword="true" /> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false" />.</returns>
public bool Equals(GorgonConstantBufferView other) => (ReferenceEquals(this, other)) && (!ViewAdjusted);

/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <param name="obj">An object to compare with this object.</param>
/// <returns><see langword="true" /> if the current object is equal to the <paramref name="obj" /> parameter; otherwise, <see langword="false" />.</returns>
public override bool Equals(object obj) => (obj is GorgonConstantBufferView cbv) && cbv.Equals(this);

/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
public override int GetHashCode() => base.GetHashCode().GenerateHash(ViewAdjusted);
#endregion

#region Constructor/Finalizer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace Gorgon.Graphics.Core
/// Returns a hash code for this instance.
/// </summary>
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
public override int GetHashCode() => 281.GenerateHash(Start).GenerateHash(Count).GenerateHash(DataType);
public override int GetHashCode() => HashCode.Combine(Start, Count, DataType);

/// <summary>
/// Initializes a new instance of the <see cref="BufferShaderViewKey"/> struct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ public enum ModeScanlineOrder

/// <summary>Returns the hash code for this instance.</summary>
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public override int GetHashCode() => 397.GenerateHash(Width).GenerateHash(Height).GenerateHash(Format).GenerateHash(RefreshRate).GenerateHash(Scaling)
.GenerateHash(ScanlineOrder).GenerateHash(SupportsStereo);
public override int GetHashCode() => HashCode.Combine(Width, Height, Format, RefreshRate, Scaling, ScanlineOrder, SupportsStereo);

/// <summary>Returns the fully qualified type name of this instance.</summary>
/// <returns>The fully qualified type name.</returns>
Expand Down
9 changes: 1 addition & 8 deletions Gorgon/Gorgon.Graphics.Core/Geometry/GorgonInputElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,7 @@ public BufferFormat Format
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => 281.GenerateHash(Context.GetHashCode())
.GenerateHash(Index)
.GenerateHash(Format)
.GenerateHash(Offset)
.GenerateHash(Slot)
.GenerateHash(Instanced.GetHashCode())
.GenerateHash(InstanceCount)
.GenerateHash(SizeInBytes);
public override int GetHashCode() => HashCode.Combine(Context, Index, Format, Offset, Slot, Instanced, InstanceCount, SizeInBytes);

/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,7 @@ namespace Gorgon.Graphics.Core
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => 281.GenerateHash(Context.GetHashCode())
.GenerateHash(Index)
.GenerateHash(StreamIndex)
.GenerateHash(StartComponent)
.GenerateHash(Slot)
.GenerateHash(ComponentCount);
public override int GetHashCode() => HashCode.Combine(Context, Index, StreamIndex, StartComponent, Slot, ComponentCount);

/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//
#endregion

using System;
using Gorgon.Core;
using Gorgon.Graphics.Core.Properties;

Expand Down Expand Up @@ -113,9 +114,7 @@ private static void IsValidBufferType(GorgonBufferCommon buffer)
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => Buffer is null
? 281.GenerateHash(Offset)
: 281.GenerateHash(Offset).GenerateHash(Buffer.GetHashCode());
public override int GetHashCode() => HashCode.Combine(Offset, Buffer);

/// <summary>
/// Determines whether the specified <see cref="object"/> is equal to this instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ public static GorgonVertexBufferBinding CreateVertexBuffer<T>(GorgonGraphics gra
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => VertexBuffer is null
? 281.GenerateHash(Stride).GenerateHash(Offset)
: 281.GenerateHash(Stride).GenerateHash(Offset).GenerateHash(VertexBuffer.GetHashCode());
public override int GetHashCode() => HashCode.Combine(Stride, Offset, VertexBuffer);

/// <summary>
/// Determines whether the specified <see cref="object"/> is equal to this instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//
#endregion

using System;
using Gorgon.Core;
using Gorgon.Graphics.Core.Properties;
using D3D11 = SharpDX.Direct3D11;
Expand Down Expand Up @@ -56,7 +57,7 @@ namespace Gorgon.Graphics.Core
#region Methods.
/// <summary>Returns a hash code for this instance.</summary>
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
public override int GetHashCode() => 281.GenerateHash(Frequency).GenerateHash(IsDisjoint);
public override int GetHashCode() => HashCode.Combine(Frequency, IsDisjoint);

/// <summary>Returns a <see cref="string" /> that represents this instance.</summary>
/// <returns>A <see cref="string" /> that represents this instance.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//
#endregion

using System;
using Gorgon.Core;
using Gorgon.Graphics.Core.Properties;

Expand Down Expand Up @@ -84,7 +85,7 @@ namespace Gorgon.Graphics.Core
/// Returns a hash code for this instance.
/// </summary>
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
public override int GetHashCode() => 281.GenerateHash(InitialCount).GenerateHash(ReadWriteView?.GetHashCode() ?? 0);
public override int GetHashCode() => HashCode.Combine(InitialCount, ReadWriteView);

/// <summary>
/// Function to determine if two instances are equal.
Expand Down
9 changes: 1 addition & 8 deletions Gorgon/Gorgon.Graphics.Core/States/GorgonBlendState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,7 @@ public bool Equals(GorgonBlendState state) => (state == this) || ((state is not
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => 281.GenerateHash(WriteMask)
.GenerateHash(AlphaBlendOperation)
.GenerateHash(ColorBlendOperation)
.GenerateHash(DestinationAlphaBlend)
.GenerateHash(DestinationColorBlend)
.GenerateHash(IsBlendingEnabled)
.GenerateHash(SourceAlphaBlend)
.GenerateHash(SourceColorBlend);
public override int GetHashCode() => HashCode.Combine(WriteMask, AlphaBlendOperation, ColorBlendOperation, DestinationAlphaBlend, DestinationColorBlend, IsBlendingEnabled, SourceAlphaBlend, SourceColorBlend);
#endregion

#region Constructor/Finalizer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,7 @@ public bool Equals(GorgonDepthStencilState info) => (info == this) || ((info is
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => 281.GenerateHash(BackFaceStencilOp)
.GenerateHash(FrontFaceStencilOp)
.GenerateHash(DepthComparison)
.GenerateHash(IsDepthEnabled)
.GenerateHash(IsDepthWriteEnabled)
.GenerateHash(IsStencilEnabled)
.GenerateHash(StencilReadMask)
.GenerateHash(StencilWriteMask);
public override int GetHashCode() => HashCode.Combine(BackFaceStencilOp, FrontFaceStencilOp, DepthComparison, IsDepthEnabled, IsDepthWriteEnabled, IsStencilEnabled, StencilReadMask, StencilWriteMask);
#endregion

#region Constructor/Finalizer.
Expand Down
Loading

0 comments on commit 4fec7cc

Please sign in to comment.