From 9596811ae710f69f4237c4111636074e26e81c4b Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 29 Jan 2024 17:23:03 +0100 Subject: [PATCH] Hashcodes --- CShocker/CShocker.csproj | 2 +- CShocker/Ranges/DurationRange.cs | 5 +++++ CShocker/Ranges/IntensityRange.cs | 5 +++++ CShocker/Ranges/RandomIntegerRange.cs | 16 ++++++++++++---- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CShocker/CShocker.csproj b/CShocker/CShocker.csproj index dc50416..97dca06 100644 --- a/CShocker/CShocker.csproj +++ b/CShocker/CShocker.csproj @@ -7,7 +7,7 @@ Glax https://github.com/C9Glax/CShocker git - 2.0.1 + 2.0.2 diff --git a/CShocker/Ranges/DurationRange.cs b/CShocker/Ranges/DurationRange.cs index 59481c6..42a5e5b 100644 --- a/CShocker/Ranges/DurationRange.cs +++ b/CShocker/Ranges/DurationRange.cs @@ -11,4 +11,9 @@ public class DurationRange : RandomIntegerRange { return obj is IntensityRange && base.Equals(obj); } + + public override int GetHashCode() + { + return HashCode.Combine("DR", base.GetHashCode()); + } } \ No newline at end of file diff --git a/CShocker/Ranges/IntensityRange.cs b/CShocker/Ranges/IntensityRange.cs index 9b57e5e..11c36d1 100644 --- a/CShocker/Ranges/IntensityRange.cs +++ b/CShocker/Ranges/IntensityRange.cs @@ -11,4 +11,9 @@ public class IntensityRange : RandomIntegerRange { return obj is IntensityRange && base.Equals(obj); } + + public override int GetHashCode() + { + return HashCode.Combine("IR", base.GetHashCode()); + } } \ No newline at end of file diff --git a/CShocker/Ranges/RandomIntegerRange.cs b/CShocker/Ranges/RandomIntegerRange.cs index eb618b3..78e2a82 100644 --- a/CShocker/Ranges/RandomIntegerRange.cs +++ b/CShocker/Ranges/RandomIntegerRange.cs @@ -2,7 +2,7 @@ public abstract class RandomIntegerRange { - public short Min, Max; + public readonly short Min, Max; internal RandomIntegerRange(short min, short max, short minLimit, short maxLimit) { if (max - min < 0) @@ -27,8 +27,16 @@ public abstract class RandomIntegerRange public override bool Equals(object? obj) { - return obj is RandomIntegerRange rir && - this.Min == rir.Min && - this.Max == rir.Max; + return obj is RandomIntegerRange rir && Equals(rir); + } + + private bool Equals(RandomIntegerRange other) + { + return Min == other.Min && Max == other.Max; + } + + public override int GetHashCode() + { + return HashCode.Combine(Min, Max); } } \ No newline at end of file