| | | 1 | | //======================================================================= |
| | | 2 | | // MaintenanceWorkBudget.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 the finite deterministic work counters consumed at one graph-maintenance boundary. |
| | | 15 | | /// </summary> |
| | | 16 | | public readonly struct MaintenanceWorkBudget : IEquatable<MaintenanceWorkBudget> |
| | | 17 | | { |
| | | 18 | | /// <summary>Creates an explicit positive maintenance budget.</summary> |
| | | 19 | | public MaintenanceWorkBudget( |
| | | 20 | | int maxConsumedEnvelopes, |
| | | 21 | | int maxBaselineAddresses, |
| | | 22 | | int maxOverlaySlots, |
| | | 23 | | int maxComponentNodes, |
| | | 24 | | int maxSeamCandidateProbes, |
| | | 25 | | int maxExplicitEdges, |
| | | 26 | | int maxDependencyEntries, |
| | | 27 | | int maxSurfaceComponentEdges = 65_536) |
| | | 28 | | { |
| | 2027 | 29 | | SwiftThrowHelper.ThrowIfArgumentOutOfRange( |
| | 2027 | 30 | | maxConsumedEnvelopes <= 0, |
| | 2027 | 31 | | maxConsumedEnvelopes, |
| | 2027 | 32 | | nameof(maxConsumedEnvelopes)); |
| | 2026 | 33 | | SwiftThrowHelper.ThrowIfArgumentOutOfRange( |
| | 2026 | 34 | | maxBaselineAddresses <= 0, |
| | 2026 | 35 | | maxBaselineAddresses, |
| | 2026 | 36 | | nameof(maxBaselineAddresses)); |
| | 2025 | 37 | | SwiftThrowHelper.ThrowIfArgumentOutOfRange( |
| | 2025 | 38 | | maxOverlaySlots <= 0, |
| | 2025 | 39 | | maxOverlaySlots, |
| | 2025 | 40 | | nameof(maxOverlaySlots)); |
| | 2024 | 41 | | SwiftThrowHelper.ThrowIfArgumentOutOfRange( |
| | 2024 | 42 | | maxComponentNodes <= 0, |
| | 2024 | 43 | | maxComponentNodes, |
| | 2024 | 44 | | nameof(maxComponentNodes)); |
| | 2023 | 45 | | SwiftThrowHelper.ThrowIfArgumentOutOfRange( |
| | 2023 | 46 | | maxSeamCandidateProbes <= 0, |
| | 2023 | 47 | | maxSeamCandidateProbes, |
| | 2023 | 48 | | nameof(maxSeamCandidateProbes)); |
| | 2022 | 49 | | SwiftThrowHelper.ThrowIfArgumentOutOfRange( |
| | 2022 | 50 | | maxExplicitEdges <= 0, |
| | 2022 | 51 | | maxExplicitEdges, |
| | 2022 | 52 | | nameof(maxExplicitEdges)); |
| | 2021 | 53 | | SwiftThrowHelper.ThrowIfArgumentOutOfRange( |
| | 2021 | 54 | | maxDependencyEntries <= 0, |
| | 2021 | 55 | | maxDependencyEntries, |
| | 2021 | 56 | | nameof(maxDependencyEntries)); |
| | 2020 | 57 | | SwiftThrowHelper.ThrowIfArgumentOutOfRange( |
| | 2020 | 58 | | maxSurfaceComponentEdges <= 0, |
| | 2020 | 59 | | maxSurfaceComponentEdges, |
| | 2020 | 60 | | nameof(maxSurfaceComponentEdges)); |
| | | 61 | | |
| | 2019 | 62 | | MaxConsumedEnvelopes = maxConsumedEnvelopes; |
| | 2019 | 63 | | MaxBaselineAddresses = maxBaselineAddresses; |
| | 2019 | 64 | | MaxOverlaySlots = maxOverlaySlots; |
| | 2019 | 65 | | MaxComponentNodes = maxComponentNodes; |
| | 2019 | 66 | | MaxSeamCandidateProbes = maxSeamCandidateProbes; |
| | 2019 | 67 | | MaxExplicitEdges = maxExplicitEdges; |
| | 2019 | 68 | | MaxDependencyEntries = maxDependencyEntries; |
| | 2019 | 69 | | MaxSurfaceComponentEdges = maxSurfaceComponentEdges; |
| | 2019 | 70 | | } |
| | | 71 | | |
| | | 72 | | /// <summary>Gets the maximum detached GridForge envelopes consumed.</summary> |
| | | 73 | | public int MaxConsumedEnvelopes { get; } |
| | | 74 | | |
| | | 75 | | /// <summary>Gets the maximum address-filtered baseline entries consumed.</summary> |
| | | 76 | | public int MaxBaselineAddresses { get; } |
| | | 77 | | |
| | | 78 | | /// <summary>Gets the maximum semantic overlay slots processed.</summary> |
| | | 79 | | public int MaxOverlaySlots { get; } |
| | | 80 | | |
| | | 81 | | /// <summary>Gets the maximum structural-component nodes processed.</summary> |
| | | 82 | | public int MaxComponentNodes { get; } |
| | | 83 | | |
| | | 84 | | /// <summary>Gets the maximum automatic-seam pair, source-address, and target-address probes.</summary> |
| | | 85 | | public int MaxSeamCandidateProbes { get; } |
| | | 86 | | |
| | | 87 | | /// <summary>Gets the maximum accepted explicit, seam, or transition edges processed.</summary> |
| | | 88 | | public int MaxExplicitEdges { get; } |
| | | 89 | | |
| | | 90 | | /// <summary>Gets the maximum dependency-index entries processed.</summary> |
| | | 91 | | public int MaxDependencyEntries { get; } |
| | | 92 | | |
| | | 93 | | /// <summary>Gets the maximum directed surface-edge candidates inspected by component work.</summary> |
| | | 94 | | public int MaxSurfaceComponentEdges { get; } |
| | | 95 | | |
| | | 96 | | /// <inheritdoc/> |
| | | 97 | | public bool Equals(MaintenanceWorkBudget other) => |
| | 8 | 98 | | MaxConsumedEnvelopes == other.MaxConsumedEnvelopes |
| | 8 | 99 | | && MaxBaselineAddresses == other.MaxBaselineAddresses |
| | 8 | 100 | | && MaxOverlaySlots == other.MaxOverlaySlots |
| | 8 | 101 | | && MaxComponentNodes == other.MaxComponentNodes |
| | 8 | 102 | | && MaxSeamCandidateProbes == other.MaxSeamCandidateProbes |
| | 8 | 103 | | && MaxExplicitEdges == other.MaxExplicitEdges |
| | 8 | 104 | | && MaxDependencyEntries == other.MaxDependencyEntries |
| | 8 | 105 | | && MaxSurfaceComponentEdges == other.MaxSurfaceComponentEdges; |
| | | 106 | | |
| | | 107 | | /// <inheritdoc/> |
| | 2 | 108 | | public override bool Equals(object? obj) => obj is MaintenanceWorkBudget other && Equals(other); |
| | | 109 | | |
| | | 110 | | /// <inheritdoc/> |
| | | 111 | | public override int GetHashCode() |
| | | 112 | | { |
| | 5 | 113 | | int hash = SwiftHashTools.CombineHashCodes(MaxConsumedEnvelopes, MaxBaselineAddresses); |
| | 5 | 114 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxOverlaySlots); |
| | 5 | 115 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxComponentNodes); |
| | 5 | 116 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxSeamCandidateProbes); |
| | 5 | 117 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxExplicitEdges); |
| | 5 | 118 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxDependencyEntries); |
| | 5 | 119 | | return SwiftHashTools.CombineHashCodes(hash, MaxSurfaceComponentEdges); |
| | | 120 | | } |
| | | 121 | | |
| | | 122 | | /// <summary>Tests two budgets for equality.</summary> |
| | | 123 | | public static bool operator ==(MaintenanceWorkBudget left, MaintenanceWorkBudget right) => |
| | 1 | 124 | | left.Equals(right); |
| | | 125 | | |
| | | 126 | | /// <summary>Tests two budgets for inequality.</summary> |
| | | 127 | | public static bool operator !=(MaintenanceWorkBudget left, MaintenanceWorkBudget right) => |
| | 1 | 128 | | !left.Equals(right); |
| | | 129 | | } |