< Summary

Information
Class: Lattice.ECS.Core.DeterministicHash
Assembly: Lattice
File(s): /home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Core/DeterministicHash.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 62
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Fnv1a32(...)0%620%
Fnv1a64(...)0%620%
GetHashCode(...)100%210%
Combine(...)100%210%

File(s)

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Core/DeterministicHash.cs

#LineLine coverage
 1// Copyright (c) 2026 Sideline Authors. All rights reserved.
 2// Licensed under GPL-3.0.
 3
 4using System;
 5using System.Runtime.CompilerServices;
 6using Lattice.Core;
 7
 8namespace Lattice.ECS.Core
 9{
 10    /// <summary>
 11    /// 确定性哈希计算 - 跨平台一致
 12    /// </summary>
 13    public static class DeterministicHash
 14    {
 15        /// <summary>FNV-1a 32位哈希</summary>
 16        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 17        public static int Fnv1a32(ReadOnlySpan<byte> data)
 18        {
 19            const uint FnvPrime = 0x01000193;
 20            const uint FnvOffset = 0x811C9DC5;
 21
 022            uint hash = FnvOffset;
 023            foreach (byte b in data)
 24            {
 025                hash ^= b;
 026                hash *= FnvPrime;
 27            }
 028            return (int)hash;
 29        }
 30
 31        /// <summary>FNV-1a 64位哈希</summary>
 32        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 33        public static long Fnv1a64(ReadOnlySpan<byte> data)
 34        {
 35            const ulong FnvPrime = 0x00000100000001B3;
 36            const ulong FnvOffset = 0xCBF29CE484222325;
 37
 038            ulong hash = FnvOffset;
 039            foreach (byte b in data)
 40            {
 041                hash ^= b;
 042                hash *= FnvPrime;
 43            }
 044            return (long)hash;
 45        }
 46
 47        /// <summary>实体引用哈希</summary>
 48        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 49        public static int GetHashCode(EntityRef entity)
 50        {
 051            return entity.Index * 59209 + entity.Version;
 52        }
 53
 54        /// <summary>组合哈希</summary>
 55        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 56        public static int Combine(int h1, int h2)
 57        {
 058            uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27);
 059            return ((int)rol5 + h1) ^ h2;
 60        }
 61    }
 62}