From 7c7ce9acb93d320bccda01d01633ad29cc7fe0ad Mon Sep 17 00:00:00 2001 From: ahmed Date: Sun, 23 Nov 2025 19:41:52 +0300 Subject: [PATCH] GetHashCode --- Esiur/Data/UUID.cs | 30 ++++++++++++++++++++++++++++-- Esiur/Esiur.csproj | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Esiur/Data/UUID.cs b/Esiur/Data/UUID.cs index 7458d50..54f155a 100644 --- a/Esiur/Data/UUID.cs +++ b/Esiur/Data/UUID.cs @@ -57,7 +57,25 @@ namespace Esiur.Data //e6 = data[offset++]; } - public UUID(byte[] data) { + public unsafe override int GetHashCode() + { + unchecked + { + fixed (byte* p = Data) + { + ulong u0 = *(ulong*)p; + ulong u1 = *(ulong*)(p + 8); + + // simple mixing of two 64-bit halves + return ((int)u0 ^ (int)(u0 >> 32)) ^ + ((int)u1 ^ (int)(u1 >> 32)); + } + } + + } + + public UUID(byte[] data) + { if (data.Length != 16) throw new Exception("UUID data size must be 16 bytes"); @@ -88,7 +106,15 @@ namespace Esiur.Data //return $"{a1.ToString("x2")}{a2.ToString("x2")}{a3.ToString("x2")}{a4.ToString("x2")}-{b1.ToString("x2")}{b2.ToString("x2")}-{c1.ToString("x2")}{c2.ToString("x2")}-{d1.ToString("x2")}{d2.ToString("x2")}-{e1.ToString("x2")}{e2.ToString("x2")}{e3.ToString("x2")}{e4.ToString("x2")}{e5.ToString("x2")}{e6.ToString("x2")}"; } - public static bool operator == (UUID a, UUID b) + public override bool Equals(object obj) + { + if (obj is UUID b) + return Data.SequenceEqual(b.Data); + + return false; + } + + public static bool operator ==(UUID a, UUID b) { return a.Data.SequenceEqual(b.Data); diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index 6d1fc7e..fc63c66 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -5,7 +5,7 @@ Ahmed Kh. Zamil http://www.esiur.com true - 2.4.13 + 2.4.14 https://github.com/esiur/esiur-dotnet Ahmed Kh. Zamil