| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationGenerationCounter.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 System; |
| | | 9 | | |
| | | 10 | | namespace Trailblazer.Pathing; |
| | | 11 | | |
| | | 12 | | /// <summary>Advances bounded identities without allowing an alias-producing wrap.</summary> |
| | | 13 | | internal static class NavigationGenerationCounter |
| | | 14 | | { |
| | 21860 | 15 | | internal static bool CanAdvance(long generation) => generation < long.MaxValue; |
| | | 16 | | |
| | 4257 | 17 | | internal static bool CanAdvance(ulong generation) => generation < ulong.MaxValue; |
| | | 18 | | |
| | | 19 | | internal static long Advance(long generation, string exhaustionMessage) |
| | | 20 | | { |
| | 21250 | 21 | | SwiftThrowHelper.ThrowIfTrue(!CanAdvance(generation), message: exhaustionMessage); |
| | 21249 | 22 | | return generation + 1; |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | internal static ulong Advance(ulong generation, string exhaustionMessage) |
| | | 26 | | { |
| | 1180 | 27 | | SwiftThrowHelper.ThrowIfTrue(!CanAdvance(generation), message: exhaustionMessage); |
| | 1179 | 28 | | return generation + 1; |
| | | 29 | | } |
| | | 30 | | } |