| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationMapCheckpointStamp.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 | | using SwiftCollections.Utility; |
| | | 10 | | |
| | | 11 | | namespace Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Identifies the exact bake and overlay prefix captured by a checkpoint rebake. |
| | | 15 | | /// </summary> |
| | | 16 | | public readonly struct NavigationMapCheckpointStamp : IEquatable<NavigationMapCheckpointStamp> |
| | | 17 | | { |
| | | 18 | | /// <summary>Initializes an immutable checkpoint base stamp.</summary> |
| | | 19 | | public NavigationMapCheckpointStamp(string mapId, long bakeVersion, long overlayHighWaterSequence) |
| | | 20 | | { |
| | 10 | 21 | | SwiftThrowHelper.ThrowIfNull(mapId, nameof(mapId)); |
| | 10 | 22 | | SwiftThrowHelper.ThrowIfArgument(string.IsNullOrWhiteSpace(mapId), nameof(mapId)); |
| | 10 | 23 | | SwiftThrowHelper.ThrowIfArgument(bakeVersion <= 0, nameof(bakeVersion)); |
| | 10 | 24 | | SwiftThrowHelper.ThrowIfArgument(overlayHighWaterSequence < 0, nameof(overlayHighWaterSequence)); |
| | | 25 | | |
| | 10 | 26 | | MapId = mapId; |
| | 10 | 27 | | BakeVersion = bakeVersion; |
| | 10 | 28 | | OverlayHighWaterSequence = overlayHighWaterSequence; |
| | 10 | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <summary>Gets the stable map identifier.</summary> |
| | | 32 | | public string MapId { get; } |
| | | 33 | | |
| | | 34 | | /// <summary>Gets the exact immutable bake version captured for the checkpoint.</summary> |
| | | 35 | | public long BakeVersion { get; } |
| | | 36 | | |
| | | 37 | | /// <summary>Gets the captured overlay operation high-water sequence.</summary> |
| | | 38 | | public long OverlayHighWaterSequence { get; } |
| | | 39 | | |
| | | 40 | | /// <inheritdoc/> |
| | | 41 | | public bool Equals(NavigationMapCheckpointStamp other) => |
| | 6 | 42 | | string.Equals(MapId, other.MapId, StringComparison.Ordinal) |
| | 6 | 43 | | && BakeVersion == other.BakeVersion |
| | 6 | 44 | | && OverlayHighWaterSequence == other.OverlayHighWaterSequence; |
| | | 45 | | |
| | | 46 | | /// <inheritdoc/> |
| | 2 | 47 | | public override bool Equals(object? obj) => obj is NavigationMapCheckpointStamp other && Equals(other); |
| | | 48 | | |
| | | 49 | | /// <inheritdoc/> |
| | | 50 | | public override int GetHashCode() |
| | | 51 | | { |
| | 4 | 52 | | int mapHash = MapId == null |
| | 4 | 53 | | ? 0 |
| | 4 | 54 | | : SwiftHashTools.GetDeterministicStringEqualityComparer().GetHashCode(MapId); |
| | 4 | 55 | | int hash = SwiftHashTools.CombineHashCodes(mapHash, BakeVersion.GetHashCode()); |
| | 4 | 56 | | return SwiftHashTools.CombineHashCodes(hash, OverlayHighWaterSequence.GetHashCode()); |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <inheritdoc/> |
| | 1 | 60 | | public static bool operator ==(NavigationMapCheckpointStamp left, NavigationMapCheckpointStamp right) => left.Equals |
| | | 61 | | |
| | | 62 | | /// <inheritdoc/> |
| | 1 | 63 | | public static bool operator !=(NavigationMapCheckpointStamp left, NavigationMapCheckpointStamp right) => !left.Equal |
| | | 64 | | } |