< Summary

Information
Class: Trailblazer.Pathing.NavigationQueryLimits
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Query/NavigationQueryLimits.cs
Line coverage
100%
Covered lines: 110
Uncovered lines: 0
Coverable lines: 110
Total lines: 281
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
ValidateWorkspace(...)100%11100%
ValidateCache(...)100%11100%
ThrowIfNonPositive(...)100%11100%
ThrowIfNonPositive(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Query/NavigationQueryLimits.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationQueryLimits.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
 8namespace Trailblazer.Pathing;
 9
 10/// <summary>Defines finite context-owned navigation query admission and retention ceilings.</summary>
 11public readonly struct NavigationQueryLimits
 12{
 13    /// <summary>The hard ceiling for one deterministic query batch.</summary>
 14    public const int MaximumBatchItems = 256;
 15
 16    /// <summary>Gets the recommended finite navigation query limits.</summary>
 17    public static NavigationQueryLimits Default { get; } = new(
 18        maxBatchItems: 8,
 19        maxBatchDescriptorBytes: 65_536,
 20        maxConcurrentNavigationQueries: 8,
 21        aStarWorkspaceMapCapacity: 16,
 22        aStarWorkspaceEndpointPageCapacity: 512,
 23        aStarWorkspaceComponentCapacity: 512,
 24        aStarWorkspaceNodeCapacity: 4_096,
 25        maxAStarCacheEntries: 128,
 26        maxAStarReusablePayloadBytes: 16_777_216,
 27        maxAStarSinglePayloadBytes: 1_159_480,
 28        maxAStarActivePayloadBytes: 4_194_304,
 29        maxAStarActivePayloadLeases: 8,
 30        flowWorkspaceMapCapacity: 16,
 31        flowWorkspaceEndpointPageCapacity: 512,
 32        flowWorkspaceComponentCapacity: 512,
 33        flowWorkspaceNodeCapacity: 4_096,
 34        rayWorkspaceCoveredAddressCapacity: 4_096,
 35        rayWorkspaceTraceIntervalCapacity: 4_096,
 36        aStarWorkspaceGuidePointCapacity: 8_191,
 37        maxFlowCacheEntries: 128,
 38        maxFlowReusablePayloadBytes: 33_554_432,
 39        maxFlowSinglePayloadBytes: 1_012_024,
 40        maxFlowActivePayloadBytes: 4_194_304,
 41        maxFlowActivePayloadLeases: 8);
 42
 43    /// <summary>Initializes explicit finite navigation query limits.</summary>
 44    public NavigationQueryLimits(
 45        int maxBatchItems,
 46        long maxBatchDescriptorBytes,
 47        int maxConcurrentNavigationQueries,
 48        int aStarWorkspaceMapCapacity,
 49        int aStarWorkspaceEndpointPageCapacity,
 50        int aStarWorkspaceComponentCapacity,
 51        int aStarWorkspaceNodeCapacity,
 52        int maxAStarCacheEntries,
 53        long maxAStarReusablePayloadBytes,
 54        long maxAStarSinglePayloadBytes,
 55        long maxAStarActivePayloadBytes,
 56        int maxAStarActivePayloadLeases,
 57        int flowWorkspaceMapCapacity,
 58        int flowWorkspaceEndpointPageCapacity,
 59        int flowWorkspaceComponentCapacity,
 60        int flowWorkspaceNodeCapacity,
 61        int rayWorkspaceCoveredAddressCapacity,
 62        int rayWorkspaceTraceIntervalCapacity,
 63        int aStarWorkspaceGuidePointCapacity,
 64        int maxFlowCacheEntries,
 65        long maxFlowReusablePayloadBytes,
 66        long maxFlowSinglePayloadBytes,
 67        long maxFlowActivePayloadBytes,
 68        int maxFlowActivePayloadLeases)
 69    {
 8970        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 8971            maxBatchItems <= 0 || maxBatchItems > MaximumBatchItems,
 8972            maxBatchItems,
 8973            nameof(maxBatchItems));
 8774        ThrowIfNonPositive(maxBatchDescriptorBytes, nameof(maxBatchDescriptorBytes));
 8775        ThrowIfNonPositive(
 8776            maxConcurrentNavigationQueries,
 8777            nameof(maxConcurrentNavigationQueries));
 8678        ValidateWorkspace(
 8679            aStarWorkspaceMapCapacity,
 8680            aStarWorkspaceEndpointPageCapacity,
 8681            aStarWorkspaceComponentCapacity,
 8682            aStarWorkspaceNodeCapacity,
 8683            nameof(aStarWorkspaceMapCapacity),
 8684            nameof(aStarWorkspaceEndpointPageCapacity),
 8685            nameof(aStarWorkspaceComponentCapacity),
 8686            nameof(aStarWorkspaceNodeCapacity));
 8587        ValidateCache(
 8588            maxAStarCacheEntries,
 8589            maxAStarReusablePayloadBytes,
 8590            maxAStarSinglePayloadBytes,
 8591            maxAStarActivePayloadBytes,
 8592            maxAStarActivePayloadLeases,
 8593            nameof(maxAStarCacheEntries),
 8594            nameof(maxAStarReusablePayloadBytes),
 8595            nameof(maxAStarSinglePayloadBytes),
 8596            nameof(maxAStarActivePayloadBytes),
 8597            nameof(maxAStarActivePayloadLeases));
 8598        ValidateWorkspace(
 8599            flowWorkspaceMapCapacity,
 85100            flowWorkspaceEndpointPageCapacity,
 85101            flowWorkspaceComponentCapacity,
 85102            flowWorkspaceNodeCapacity,
 85103            nameof(flowWorkspaceMapCapacity),
 85104            nameof(flowWorkspaceEndpointPageCapacity),
 85105            nameof(flowWorkspaceComponentCapacity),
 85106            nameof(flowWorkspaceNodeCapacity));
 84107        ThrowIfNonPositive(
 84108            rayWorkspaceCoveredAddressCapacity,
 84109            nameof(rayWorkspaceCoveredAddressCapacity));
 83110        ThrowIfNonPositive(
 83111            rayWorkspaceTraceIntervalCapacity,
 83112            nameof(rayWorkspaceTraceIntervalCapacity));
 82113        SwiftThrowHelper.ThrowIfArgument(
 82114            rayWorkspaceTraceIntervalCapacity > rayWorkspaceCoveredAddressCapacity,
 82115            nameof(rayWorkspaceTraceIntervalCapacity),
 82116            "Trace-interval capacity cannot exceed covered-address capacity.");
 81117        ThrowIfNonPositive(
 81118            aStarWorkspaceGuidePointCapacity,
 81119            nameof(aStarWorkspaceGuidePointCapacity));
 80120        SwiftThrowHelper.ThrowIfArgument(
 80121            aStarWorkspaceGuidePointCapacity < aStarWorkspaceNodeCapacity,
 80122            nameof(aStarWorkspaceGuidePointCapacity),
 80123            "A* guide-point capacity must cover every admitted search node.");
 80124        ValidateCache(
 80125            maxFlowCacheEntries,
 80126            maxFlowReusablePayloadBytes,
 80127            maxFlowSinglePayloadBytes,
 80128            maxFlowActivePayloadBytes,
 80129            maxFlowActivePayloadLeases,
 80130            nameof(maxFlowCacheEntries),
 80131            nameof(maxFlowReusablePayloadBytes),
 80132            nameof(maxFlowSinglePayloadBytes),
 80133            nameof(maxFlowActivePayloadBytes),
 80134            nameof(maxFlowActivePayloadLeases));
 135
 80136        MaxBatchItems = maxBatchItems;
 80137        MaxBatchDescriptorBytes = maxBatchDescriptorBytes;
 80138        MaxConcurrentNavigationQueries = maxConcurrentNavigationQueries;
 80139        AStarWorkspaceMapCapacity = aStarWorkspaceMapCapacity;
 80140        AStarWorkspaceEndpointPageCapacity = aStarWorkspaceEndpointPageCapacity;
 80141        AStarWorkspaceComponentCapacity = aStarWorkspaceComponentCapacity;
 80142        AStarWorkspaceNodeCapacity = aStarWorkspaceNodeCapacity;
 80143        MaxAStarCacheEntries = maxAStarCacheEntries;
 80144        MaxAStarReusablePayloadBytes = maxAStarReusablePayloadBytes;
 80145        MaxAStarSinglePayloadBytes = maxAStarSinglePayloadBytes;
 80146        MaxAStarActivePayloadBytes = maxAStarActivePayloadBytes;
 80147        MaxAStarActivePayloadLeases = maxAStarActivePayloadLeases;
 80148        FlowWorkspaceMapCapacity = flowWorkspaceMapCapacity;
 80149        FlowWorkspaceEndpointPageCapacity = flowWorkspaceEndpointPageCapacity;
 80150        FlowWorkspaceComponentCapacity = flowWorkspaceComponentCapacity;
 80151        FlowWorkspaceNodeCapacity = flowWorkspaceNodeCapacity;
 80152        RayWorkspaceCoveredAddressCapacity = rayWorkspaceCoveredAddressCapacity;
 80153        RayWorkspaceTraceIntervalCapacity = rayWorkspaceTraceIntervalCapacity;
 80154        AStarWorkspaceGuidePointCapacity = aStarWorkspaceGuidePointCapacity;
 80155        MaxFlowCacheEntries = maxFlowCacheEntries;
 80156        MaxFlowReusablePayloadBytes = maxFlowReusablePayloadBytes;
 80157        MaxFlowSinglePayloadBytes = maxFlowSinglePayloadBytes;
 80158        MaxFlowActivePayloadBytes = maxFlowActivePayloadBytes;
 80159        MaxFlowActivePayloadLeases = maxFlowActivePayloadLeases;
 80160    }
 161
 162    /// <summary>Gets the maximum query descriptors accepted by one batch.</summary>
 163    public int MaxBatchItems { get; }
 164
 165    /// <summary>Gets the maximum logical bytes accepted for submitted batch descriptors.</summary>
 166    public long MaxBatchDescriptorBytes { get; }
 167
 168    /// <summary>Gets the aggregate maximum concurrently admitted A* and Flow queries.</summary>
 169    public int MaxConcurrentNavigationQueries { get; }
 170
 171    /// <summary>Gets the map capacity of each exclusive A* workspace.</summary>
 172    public int AStarWorkspaceMapCapacity { get; }
 173
 174    /// <summary>Gets the endpoint-page capacity of each exclusive A* workspace.</summary>
 175    public int AStarWorkspaceEndpointPageCapacity { get; }
 176
 177    /// <summary>Gets the component-dependency capacity of each exclusive A* workspace.</summary>
 178    public int AStarWorkspaceComponentCapacity { get; }
 179
 180    /// <summary>Gets the node capacity of each exclusive A* workspace.</summary>
 181    public int AStarWorkspaceNodeCapacity { get; }
 182
 183    /// <summary>Gets the maximum reusable A* payload count.</summary>
 184    public int MaxAStarCacheEntries { get; }
 185
 186    /// <summary>Gets the maximum reusable A* payload bytes.</summary>
 187    public long MaxAStarReusablePayloadBytes { get; }
 188
 189    /// <summary>Gets the maximum bytes retained by one A* payload.</summary>
 190    public long MaxAStarSinglePayloadBytes { get; }
 191
 192    /// <summary>Gets the maximum bytes retained by active A* payloads.</summary>
 193    public long MaxAStarActivePayloadBytes { get; }
 194
 195    /// <summary>Gets the maximum active and reserved A* payload lease count.</summary>
 196    public int MaxAStarActivePayloadLeases { get; }
 197
 198    /// <summary>Gets the map capacity of each exclusive Flow workspace.</summary>
 199    public int FlowWorkspaceMapCapacity { get; }
 200
 201    /// <summary>Gets the endpoint and dependency-page capacity of each exclusive Flow workspace.</summary>
 202    public int FlowWorkspaceEndpointPageCapacity { get; }
 203
 204    /// <summary>Gets the component-dependency capacity of each exclusive Flow workspace.</summary>
 205    public int FlowWorkspaceComponentCapacity { get; }
 206
 207    /// <summary>Gets the node capacity of each exclusive Flow workspace.</summary>
 208    public int FlowWorkspaceNodeCapacity { get; }
 209
 210    /// <summary>Gets the covered-address capacity of each navigation-ray workspace.</summary>
 211    public int RayWorkspaceCoveredAddressCapacity { get; }
 212
 213    /// <summary>Gets the ordered trace-interval capacity of each navigation-ray workspace.</summary>
 214    public int RayWorkspaceTraceIntervalCapacity { get; }
 215
 216    /// <summary>Gets the raw and simplified guide-point capacity of each A* workspace.</summary>
 217    public int AStarWorkspaceGuidePointCapacity { get; }
 218
 219    /// <summary>Gets the maximum reusable Flow payload count.</summary>
 220    public int MaxFlowCacheEntries { get; }
 221
 222    /// <summary>Gets the maximum reusable Flow payload bytes.</summary>
 223    public long MaxFlowReusablePayloadBytes { get; }
 224
 225    /// <summary>Gets the maximum bytes retained by one Flow payload.</summary>
 226    public long MaxFlowSinglePayloadBytes { get; }
 227
 228    /// <summary>Gets the maximum bytes retained by unique active Flow payloads.</summary>
 229    public long MaxFlowActivePayloadBytes { get; }
 230
 231    /// <summary>Gets the maximum active and reserved Flow payload lease count.</summary>
 232    public int MaxFlowActivePayloadLeases { get; }
 233
 234    private static void ValidateWorkspace(
 235        int mapCapacity,
 236        int pageCapacity,
 237        int componentCapacity,
 238        int nodeCapacity,
 239        string mapName,
 240        string pageName,
 241        string componentName,
 242        string nodeName)
 243    {
 171244        SwiftThrowHelper.ThrowIfNegative(mapCapacity, mapName);
 171245        SwiftThrowHelper.ThrowIfNegative(pageCapacity, pageName);
 171246        SwiftThrowHelper.ThrowIfNegative(componentCapacity, componentName);
 169247        SwiftThrowHelper.ThrowIfNegative(nodeCapacity, nodeName);
 169248    }
 249
 250    private static void ValidateCache(
 251        int entries,
 252        long reusableBytes,
 253        long singleBytes,
 254        long activeBytes,
 255        int activeLeases,
 256        string entriesName,
 257        string reusableName,
 258        string singleName,
 259        string activeName,
 260        string leaseName)
 261    {
 165262        SwiftThrowHelper.ThrowIfNegative(entries, entriesName);
 165263        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 165264            reusableBytes < 0,
 165265            null,
 165266            reusableName);
 165267        ThrowIfNonPositive(singleBytes, singleName);
 165268        ThrowIfNonPositive(activeBytes, activeName);
 165269        SwiftThrowHelper.ThrowIfArgument(
 165270            singleBytes > activeBytes,
 165271            singleName,
 165272            "A single payload cannot exceed the complete active-payload byte ceiling.");
 165273        ThrowIfNonPositive(activeLeases, leaseName);
 165274    }
 275
 276    private static void ThrowIfNonPositive(int value, string parameterName) =>
 500277        SwiftThrowHelper.ThrowIfArgumentOutOfRange(value <= 0, value, parameterName);
 278
 279    private static void ThrowIfNonPositive(long value, string parameterName) =>
 417280        SwiftThrowHelper.ThrowIfArgumentOutOfRange(value <= 0, null, parameterName);
 281}