Added GetHashCode to UnsafeBitSet

This commit is contained in:
2025-12-03 20:03:42 +09:00
parent 0ad4322058
commit c152e4383d
2 changed files with 18 additions and 6 deletions

View File

@@ -1,11 +1,9 @@
using Misaki.HighPerformance.LowLevel.Buffer; using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Contracts; using Misaki.HighPerformance.LowLevel.Contracts;
using Misaki.HighPerformance.LowLevel.Utilities; using Misaki.HighPerformance.LowLevel.Utilities;
using System.Collections;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using System.Text; using System.Text;
namespace Misaki.HighPerformance.LowLevel.Collections; namespace Misaki.HighPerformance.LowLevel.Collections;
@@ -684,6 +682,13 @@ public unsafe struct UnsafeBitSet : IDisposable
return span[.._bits.Count]; return span[.._bits.Count];
} }
public readonly override int GetHashCode()
{
var hash = new HashCode();
hash.AddBytes(MemoryMarshal.AsBytes(_bits.AsSpan()));
return hash.ToHashCode();
}
public readonly override string ToString() public readonly override string ToString()
{ {
// Convert uint to binary form for pretty printing // Convert uint to binary form for pretty printing
@@ -835,6 +840,13 @@ public readonly ref struct SpanBitSet
return span[.._bits.Length]; return span[.._bits.Length];
} }
public override int GetHashCode()
{
var hash = new HashCode();
hash.AddBytes(MemoryMarshal.AsBytes(_bits));
return hash.ToHashCode();
}
public override string ToString() public override string ToString()
{ {
// Convert uint to binary form for pretty printing // Convert uint to binary form for pretty printing

View File

@@ -6,7 +6,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Authors>Misaki</Authors> <Authors>Misaki</Authors>
<AssemblyVersion>1.2.5</AssemblyVersion> <AssemblyVersion>1.2.6</AssemblyVersion>
<Version>$(AssemblyVersion)</Version> <Version>$(AssemblyVersion)</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageProjectUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</PackageProjectUrl> <PackageProjectUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</PackageProjectUrl>