| | | 1 | | //======================================================================= |
| | | 2 | | // GuideSampleWorkBudget.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 | | /// Defines finite deterministic work limits for one guide sampling operation. |
| | | 15 | | /// </summary> |
| | | 16 | | public readonly struct GuideSampleWorkBudget : IEquatable<GuideSampleWorkBudget> |
| | | 17 | | { |
| | | 18 | | /// <summary>Gets the maximum number of current-node lookup probes.</summary> |
| | | 19 | | public int MaxCurrentNodeLookupProbes { get; } |
| | | 20 | | |
| | | 21 | | /// <summary>Gets the maximum number of cursor-leg scans.</summary> |
| | | 22 | | public int MaxCursorLegScans { get; } |
| | | 23 | | |
| | | 24 | | /// <summary>Gets the maximum number of cursor rebases.</summary> |
| | | 25 | | public int MaxCursorRebases { get; } |
| | | 26 | | |
| | | 27 | | /// <summary>Gets the maximum number of portal checks.</summary> |
| | | 28 | | public int MaxPortalChecks { get; } |
| | | 29 | | |
| | | 30 | | /// <summary>Gets the maximum number of prism checks.</summary> |
| | | 31 | | public int MaxPrismChecks { get; } |
| | | 32 | | |
| | | 33 | | /// <summary>Gets the maximum number of trace intervals visited.</summary> |
| | | 34 | | public int MaxTraceIntervals { get; } |
| | | 35 | | |
| | | 36 | | /// <summary>Gets the maximum number of local recovery attempts.</summary> |
| | | 37 | | public int MaxLocalRecoveryAttempts { get; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Creates a finite guide sample work budget. Zero disables the corresponding category of work. |
| | | 41 | | /// </summary> |
| | | 42 | | /// <exception cref="ArgumentOutOfRangeException">Thrown when any limit is negative.</exception> |
| | | 43 | | public GuideSampleWorkBudget( |
| | | 44 | | int maxCurrentNodeLookupProbes, |
| | | 45 | | int maxCursorLegScans, |
| | | 46 | | int maxCursorRebases, |
| | | 47 | | int maxPortalChecks, |
| | | 48 | | int maxPrismChecks, |
| | | 49 | | int maxTraceIntervals, |
| | | 50 | | int maxLocalRecoveryAttempts) |
| | | 51 | | { |
| | 1428 | 52 | | SwiftThrowHelper.ThrowIfNegative(maxCurrentNodeLookupProbes, nameof(maxCurrentNodeLookupProbes)); |
| | 1427 | 53 | | SwiftThrowHelper.ThrowIfNegative(maxCursorLegScans, nameof(maxCursorLegScans)); |
| | 1426 | 54 | | SwiftThrowHelper.ThrowIfNegative(maxCursorRebases, nameof(maxCursorRebases)); |
| | 1425 | 55 | | SwiftThrowHelper.ThrowIfNegative(maxPortalChecks, nameof(maxPortalChecks)); |
| | 1424 | 56 | | SwiftThrowHelper.ThrowIfNegative(maxPrismChecks, nameof(maxPrismChecks)); |
| | 1423 | 57 | | SwiftThrowHelper.ThrowIfNegative(maxTraceIntervals, nameof(maxTraceIntervals)); |
| | 1422 | 58 | | SwiftThrowHelper.ThrowIfNegative(maxLocalRecoveryAttempts, nameof(maxLocalRecoveryAttempts)); |
| | | 59 | | |
| | 1421 | 60 | | MaxCurrentNodeLookupProbes = maxCurrentNodeLookupProbes; |
| | 1421 | 61 | | MaxCursorLegScans = maxCursorLegScans; |
| | 1421 | 62 | | MaxCursorRebases = maxCursorRebases; |
| | 1421 | 63 | | MaxPortalChecks = maxPortalChecks; |
| | 1421 | 64 | | MaxPrismChecks = maxPrismChecks; |
| | 1421 | 65 | | MaxTraceIntervals = maxTraceIntervals; |
| | 1421 | 66 | | MaxLocalRecoveryAttempts = maxLocalRecoveryAttempts; |
| | 1421 | 67 | | } |
| | | 68 | | |
| | | 69 | | /// <inheritdoc/> |
| | | 70 | | public bool Equals(GuideSampleWorkBudget other) => |
| | 14 | 71 | | MaxCurrentNodeLookupProbes == other.MaxCurrentNodeLookupProbes |
| | 14 | 72 | | && MaxCursorLegScans == other.MaxCursorLegScans |
| | 14 | 73 | | && MaxCursorRebases == other.MaxCursorRebases |
| | 14 | 74 | | && MaxPortalChecks == other.MaxPortalChecks |
| | 14 | 75 | | && MaxPrismChecks == other.MaxPrismChecks |
| | 14 | 76 | | && MaxTraceIntervals == other.MaxTraceIntervals |
| | 14 | 77 | | && MaxLocalRecoveryAttempts == other.MaxLocalRecoveryAttempts; |
| | | 78 | | |
| | | 79 | | /// <inheritdoc/> |
| | 6 | 80 | | public override bool Equals(object? obj) => obj is GuideSampleWorkBudget other && Equals(other); |
| | | 81 | | |
| | | 82 | | /// <inheritdoc/> |
| | | 83 | | public override int GetHashCode() |
| | | 84 | | { |
| | 2 | 85 | | int hash = SwiftHashTools.CombineHashCodes(MaxCurrentNodeLookupProbes, MaxCursorLegScans); |
| | 2 | 86 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxCursorRebases); |
| | 2 | 87 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxPortalChecks); |
| | 2 | 88 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxPrismChecks); |
| | 2 | 89 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxTraceIntervals); |
| | 2 | 90 | | return SwiftHashTools.CombineHashCodes(hash, MaxLocalRecoveryAttempts); |
| | | 91 | | } |
| | | 92 | | |
| | | 93 | | /// <summary>Returns whether two budgets have exactly equal limits.</summary> |
| | 1 | 94 | | public static bool operator ==(GuideSampleWorkBudget left, GuideSampleWorkBudget right) => left.Equals(right); |
| | | 95 | | |
| | | 96 | | /// <summary>Returns whether two budgets differ.</summary> |
| | 1 | 97 | | public static bool operator !=(GuideSampleWorkBudget left, GuideSampleWorkBudget right) => !left.Equals(right); |
| | | 98 | | } |