Files
hjha-server/ServerCore/Helper/HashCodeHelper.cs
xiaoou e9616125ce feat: initial commit - HJHA game server full source
6 major server modules (PdkFriendServer/GlobalSever/ServerCore/GameModule/GameNetModule) +
game logic (GameFix/GameDAL/ServerData) +
network layer (NetWorkMessage) +
data layer (ObjectModel) +
utilities (MrWu/Core/Config/CloudAPI/dll) +
adapters (zyxAdapter/base)

.NET 8.0 C# solution, 16 projects, 958 source files
2026-07-07 12:02:15 +08:00

69 lines
2.5 KiB
C#

using System.Runtime.CompilerServices;
namespace Server.Core
{
public static class HashCodeHelper
{
private const int _hashMultiplier = 0x15745F5;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Combine(int h1, int h2)
{
// 使用与 .NET Core 相同的算法进行哈希合并
unchecked
{
uint r = (uint)(h1 * _hashMultiplier + h2);
return (int)((r << 3) | (r >> 29)); // ROTL32(r, 3)
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint Combine(uint h1, uint h2)
{
// 使用与 .NET Core 相同的算法进行哈希合并
unchecked
{
uint r = (uint)(h1 * _hashMultiplier + h2);
return ((r << 3) | (r >> 29)); // ROTL32(r, 3)
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint Combine<T1,T2,T3>(T1 value1, T2 value2, T3 value3)
{
uint h1 = (object) value1 != null ? (uint) value1.GetHashCode() : 0U;
uint h2 = (object) value2 != null ? (uint) value2.GetHashCode() : 0U;
uint h3 = (object) value3 != null ? (uint) value3.GetHashCode() : 0U;
unchecked
{
return Combine(Combine(h1, h2),h3);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint Combine<T1,T2,T3,T4>(T1 value1, T2 value2, T3 value3, T4 value4)
{
uint h1 = (object) value1 != null ? (uint) value1.GetHashCode() : 0U;
uint h2 = (object) value2 != null ? (uint) value2.GetHashCode() : 0U;
unchecked
{
return Combine(Combine(h1,h2),value3,value4);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint Combine<T1,T2,T3,T4,T5>(T1 value1, T2 value2, T3 value3, T4 value4,T5 value5)
{
uint h1 = (object) value1 != null ? (uint) value1.GetHashCode() : 0U;
uint h2 = (object) value2 != null ? (uint) value2.GetHashCode() : 0U;
unchecked
{
return Combine(Combine(h1, h2),value3,value4,value5);
}
}
// 可根据需要继续添加更多参数版本...
}
}