| | | 1 | | //======================================================================= |
| | | 2 | | // GridCoveredAddressRunStamp.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 GridForge.Grids.Topology; |
| | | 12 | | |
| | | 13 | | /// <summary>Identifies the exact committed world revision bound by a covered-address cursor.</summary> |
| | | 14 | | public readonly struct GridCoveredAddressRunStamp : IEquatable<GridCoveredAddressRunStamp> |
| | | 15 | | { |
| | | 16 | | /// <summary>The process-unique world allocation identity.</summary> |
| | | 17 | | public long WorldSpawnToken { get; } |
| | | 18 | | |
| | | 19 | | /// <summary>The world-local structural generation.</summary> |
| | | 20 | | public uint WorldVersion { get; } |
| | | 21 | | |
| | | 22 | | /// <summary>The committed world-local change sequence.</summary> |
| | | 23 | | public ulong ChangeSequence { get; } |
| | | 24 | | |
| | | 25 | | internal GridCoveredAddressRunStamp( |
| | | 26 | | long worldSpawnToken, |
| | | 27 | | uint worldVersion, |
| | | 28 | | ulong changeSequence) |
| | | 29 | | { |
| | 53 | 30 | | WorldSpawnToken = worldSpawnToken; |
| | 53 | 31 | | WorldVersion = worldVersion; |
| | 53 | 32 | | ChangeSequence = changeSequence; |
| | 53 | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <inheritdoc /> |
| | | 36 | | public bool Equals(GridCoveredAddressRunStamp other) => |
| | 13 | 37 | | WorldSpawnToken == other.WorldSpawnToken |
| | 13 | 38 | | && WorldVersion == other.WorldVersion |
| | 13 | 39 | | && ChangeSequence == other.ChangeSequence; |
| | | 40 | | |
| | | 41 | | /// <inheritdoc /> |
| | | 42 | | public override bool Equals(object? obj) => |
| | 3 | 43 | | obj is GridCoveredAddressRunStamp other && Equals(other); |
| | | 44 | | |
| | | 45 | | /// <inheritdoc /> |
| | | 46 | | public override int GetHashCode() |
| | | 47 | | { |
| | 2 | 48 | | int hash = SwiftHashTools.CombineHashCodes( |
| | 2 | 49 | | WorldSpawnToken.GetHashCode(), |
| | 2 | 50 | | WorldVersion.GetHashCode()); |
| | 2 | 51 | | return SwiftHashTools.CombineHashCodes(hash, ChangeSequence.GetHashCode()); |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <inheritdoc /> |
| | | 55 | | public static bool operator ==( |
| | | 56 | | GridCoveredAddressRunStamp left, |
| | 2 | 57 | | GridCoveredAddressRunStamp right) => left.Equals(right); |
| | | 58 | | |
| | | 59 | | /// <inheritdoc /> |
| | | 60 | | public static bool operator !=( |
| | | 61 | | GridCoveredAddressRunStamp left, |
| | 1 | 62 | | GridCoveredAddressRunStamp right) => !left.Equals(right); |
| | | 63 | | } |