| | | 1 | | //======================================================================= |
| | | 2 | | // GridNavigationBodyTraceScratch.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 | | |
| | | 8 | | using SwiftCollections; |
| | | 9 | | |
| | | 10 | | namespace GridForge.Grids; |
| | | 11 | | |
| | | 12 | | /// <summary>Owns reusable caller-side storage for allocation-free warmed navigation-body traces.</summary> |
| | | 13 | | /// <remarks>Instances retain capacity and are not thread-safe.</remarks> |
| | | 14 | | public sealed class GridNavigationBodyTraceScratch |
| | | 15 | | { |
| | | 16 | | internal SwiftList<ushort> CandidateGrids { get; } |
| | | 17 | | |
| | | 18 | | internal SwiftList<GridNavigationBodyTraceCandidate> AddressCandidates { get; } |
| | | 19 | | |
| | | 20 | | internal SwiftList<int> UnionMembers { get; } |
| | | 21 | | |
| | | 22 | | /// <summary>Creates scratch with expected grid and address counts.</summary> |
| | 155 | 23 | | public GridNavigationBodyTraceScratch(int gridCapacity = 0, int addressCapacity = 0) |
| | | 24 | | { |
| | 155 | 25 | | ChronicleGuard.ThrowIfNegative(gridCapacity, nameof(gridCapacity)); |
| | 155 | 26 | | ChronicleGuard.ThrowIfNegative(addressCapacity, nameof(addressCapacity)); |
| | | 27 | | |
| | 155 | 28 | | CandidateGrids = new SwiftList<ushort>(gridCapacity); |
| | 155 | 29 | | AddressCandidates = new SwiftList<GridNavigationBodyTraceCandidate>(addressCapacity); |
| | 155 | 30 | | UnionMembers = new SwiftList<int>(addressCapacity); |
| | 155 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary>Clears temporary values while retaining capacity.</summary> |
| | | 34 | | public void Clear() |
| | | 35 | | { |
| | 918 | 36 | | CandidateGrids.Clear(); |
| | 918 | 37 | | AddressCandidates.Clear(); |
| | 918 | 38 | | UnionMembers.Clear(); |
| | 918 | 39 | | } |
| | | 40 | | } |