< Summary

Information
Class: GridForge.Grids.GridTraceIntervalScratch
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Grids/Support/GridTraceIntervalScratch.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 64
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Clear()100%11100%
Enter()100%11100%
Exit()100%11100%
ThrowIfActive()100%11100%
ClearCore()100%11100%

File(s)

/home/runner/work/GridForge/GridForge/src/GridForge/Grids/Support/GridTraceIntervalScratch.cs

#LineLine coverage
 1//=======================================================================
 2// GridTraceIntervalScratch.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 SwiftCollections;
 9
 10namespace GridForge.Grids;
 11
 12/// <summary>
 13/// Owns reusable caller-side storage for allocation-free warmed interval traces.
 14/// </summary>
 15/// <remarks>
 16/// Instances retain capacity and are not thread-safe. Reentrant tracing or clearing an active instance
 17/// throws before caller output is modified. Completed traces release temporary grid references.
 18/// </remarks>
 19public sealed class GridTraceIntervalScratch
 20{
 21    private bool _isActive;
 22    internal SwiftList<ushort> CandidateGrids { get; }
 23
 24    internal SwiftList<GridTraceAddressCandidate> AddressCandidates { get; }
 25
 26    /// <summary>Creates trace scratch with optional expected grid and address counts.</summary>
 14627    public GridTraceIntervalScratch(int gridCapacity = 0, int addressCapacity = 0)
 28    {
 14629        ChronicleGuard.ThrowIfNegative(gridCapacity, nameof(gridCapacity));
 14630        ChronicleGuard.ThrowIfNegative(addressCapacity, nameof(addressCapacity));
 31
 14632        CandidateGrids = new SwiftList<ushort>(gridCapacity);
 14633        AddressCandidates = new SwiftList<GridTraceAddressCandidate>(addressCapacity);
 14634    }
 35
 36    /// <summary>Clears temporary values while retaining capacity.</summary>
 37    public void Clear()
 38    {
 5439        ThrowIfActive();
 5340        ClearCore();
 5341    }
 42
 43    internal void Enter()
 44    {
 28745        ThrowIfActive();
 28546        _isActive = true;
 28547        ClearCore();
 28548    }
 49
 50    internal void Exit()
 51    {
 28552        ClearCore();
 28553        _isActive = false;
 28554    }
 55
 34156    private void ThrowIfActive() => ChronicleGuard.ThrowIfTrue(
 34157        _isActive, nameof(GridTraceIntervalScratch), "Interval trace scratch is already in use.");
 58
 59    private void ClearCore()
 60    {
 62361        CandidateGrids.Clear();
 62362        AddressCandidates.Clear();
 62363    }
 64}