< Summary

Information
Class: Trailblazer.Pathing.GraphDependencyStamp
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Graph/GraphDependencyStamp.cs
Line coverage
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 169
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)100%22100%
get_RetainedBytes()100%11100%
GetRetainedBytes(...)100%11100%
GetArrayRetainedBytes(...)100%22100%
GetArrayRetainedBytes(...)100%22100%
Align8(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Graph/GraphDependencyStamp.cs

#LineLine coverage
 1//=======================================================================
 2// GraphDependencyStamp.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System;
 9using SwiftCollections.Utility;
 10
 11namespace Trailblazer.Pathing;
 12
 13/// <summary>Captures exact immutable component and page dependencies without a global graph version.</summary>
 14internal sealed class GraphDependencyStamp
 15{
 16    private const long ObjectHeaderBytes = 16L;
 17    private const long ArrayHeaderBytes = 24L;
 18    private const long ReferenceSlotBytes = 8L;
 19    private const long Int64Bytes = 8L;
 20    private const long NavigationAreaPolicyKeyBytes = ReferenceSlotBytes + Int64Bytes;
 21    private const long GraphComponentDependencyBytes = 32L;
 22    private const long GraphPageDependencyBytes = 56L;
 123    private static readonly long BaseRetainedBytes = Align8(
 124        ObjectHeaderBytes
 125        + NavigationAreaPolicyKeyBytes
 126        + (2L * ReferenceSlotBytes)
 127        + Int64Bytes
 128        + Int64Bytes);
 29
 95030    internal GraphDependencyStamp(
 95031        NavigationAreaPolicyKey areaPolicy,
 95032        GraphComponentDependency[] components,
 95033        GraphPageDependency[] pages,
 95034        bool hasTransitionRuleDependency = false,
 95035        long transitionRuleVersion = 0)
 36    {
 95037        AreaPolicy = areaPolicy;
 95038        Components = components;
 95039        Pages = pages;
 95040        HasTransitionRuleDependency = hasTransitionRuleDependency;
 95041        TransitionRuleVersion = hasTransitionRuleDependency ? transitionRuleVersion : 0;
 95042    }
 43
 44    internal NavigationAreaPolicyKey AreaPolicy { get; }
 45
 46    internal GraphComponentDependency[] Components { get; }
 47
 48    internal GraphPageDependency[] Pages { get; }
 49
 50    internal bool HasTransitionRuleDependency { get; }
 51
 52    internal long TransitionRuleVersion { get; }
 53
 1135554    internal long RetainedBytes => checked(
 1135555        BaseRetainedBytes
 1135556        + GetArrayRetainedBytes(Components, GraphComponentDependencyBytes)
 1135557        + GetArrayRetainedBytes(Pages, GraphPageDependencyBytes));
 58
 59    internal static long GetRetainedBytes(int componentCount, int pageCount)
 60    {
 120061        SwiftThrowHelper.ThrowIfNegative(componentCount, nameof(componentCount));
 120062        SwiftThrowHelper.ThrowIfNegative(pageCount, nameof(pageCount));
 120063        return checked(
 120064            BaseRetainedBytes
 120065            + GetArrayRetainedBytes(componentCount, GraphComponentDependencyBytes)
 120066            + GetArrayRetainedBytes(pageCount, GraphPageDependencyBytes));
 67    }
 68
 69    private static long GetArrayRetainedBytes<T>(T[] values, long elementBytes) =>
 2271070        values.Length == 0
 2271071            ? 0L
 2271072            : Align8(checked(ArrayHeaderBytes + ((long)values.Length * elementBytes)));
 73
 74    private static long GetArrayRetainedBytes(int length, long elementBytes) =>
 240075        length == 0
 240076            ? 0L
 240077            : Align8(checked(ArrayHeaderBytes + ((long)length * elementBytes)));
 78
 2506879    private static long Align8(long value) => checked((value + 7L) & ~7L);
 80}
 81
 82/// <summary>Identifies one structural component generation.</summary>
 83internal readonly struct GraphComponentDependency : IEquatable<GraphComponentDependency>
 84{
 85    internal GraphComponentDependency(NavigationSurfaceComponentKey key, long version)
 86    {
 87        Key = key;
 88        Version = version;
 89    }
 90
 91    internal NavigationSurfaceComponentKey Key { get; }
 92
 93    internal long Version { get; }
 94
 95    public bool Equals(GraphComponentDependency other) =>
 96        Key.Equals(other.Key)
 97        && Version == other.Version;
 98
 99    public override int GetHashCode()
 100    {
 101        return SwiftHashTools.CombineHashCodes(Key.GetHashCode(), Version.GetHashCode());
 102    }
 103}
 104
 105/// <summary>Names one exact map-local page whose versions a query consumed.</summary>
 106internal readonly struct GraphPageDependencyAddress
 107{
 108    internal GraphPageDependencyAddress(string mapId, int pageIndex)
 109    {
 110        MapId = mapId;
 111        PageIndex = pageIndex;
 112    }
 113
 114    internal string MapId { get; }
 115
 116    internal int PageIndex { get; }
 117}
 118
 119/// <summary>Identifies one map-local semantic and physical page generation.</summary>
 120internal readonly struct GraphPageDependency : IEquatable<GraphPageDependency>
 121{
 122    internal GraphPageDependency(
 123        string mapId,
 124        long bakeVersion,
 125        long dynamicSlotGeneration,
 126        int pageIndex,
 127        long semanticVersion,
 128        long physicalVersion,
 129        long transitionVersion = 0)
 130    {
 131        MapId = mapId;
 132        BakeVersion = bakeVersion;
 133        DynamicSlotGeneration = dynamicSlotGeneration;
 134        PageIndex = pageIndex;
 135        SemanticVersion = semanticVersion;
 136        PhysicalVersion = physicalVersion;
 137        TransitionVersion = transitionVersion;
 138    }
 139
 140    internal string MapId { get; }
 141    internal long BakeVersion { get; }
 142    internal long DynamicSlotGeneration { get; }
 143    internal int PageIndex { get; }
 144    internal long SemanticVersion { get; }
 145    internal long PhysicalVersion { get; }
 146    internal long TransitionVersion { get; }
 147
 148    public bool Equals(GraphPageDependency other) =>
 149        string.Equals(MapId, other.MapId, StringComparison.Ordinal)
 150        && BakeVersion == other.BakeVersion
 151        && DynamicSlotGeneration == other.DynamicSlotGeneration
 152        && PageIndex == other.PageIndex
 153        && SemanticVersion == other.SemanticVersion
 154        && PhysicalVersion == other.PhysicalVersion
 155        && TransitionVersion == other.TransitionVersion;
 156
 157    public override int GetHashCode()
 158    {
 159        int mapHash = MapId == null
 160            ? 0
 161            : SwiftHashTools.GetDeterministicStringEqualityComparer().GetHashCode(MapId);
 162        int hash = SwiftHashTools.CombineHashCodes(mapHash, BakeVersion.GetHashCode());
 163        hash = SwiftHashTools.CombineHashCodes(hash, DynamicSlotGeneration.GetHashCode());
 164        hash = SwiftHashTools.CombineHashCodes(hash, PageIndex);
 165        hash = SwiftHashTools.CombineHashCodes(hash, SemanticVersion.GetHashCode());
 166        hash = SwiftHashTools.CombineHashCodes(hash, PhysicalVersion.GetHashCode());
 167        return SwiftHashTools.CombineHashCodes(hash, TransitionVersion.GetHashCode());
 168    }
 169}