| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationTransitionRuleTable.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 System.Runtime.CompilerServices; |
| | | 10 | | |
| | | 11 | | namespace Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | /// <summary>Stores one exact-size, immutable, globally ID-sorted rule array.</summary> |
| | | 14 | | internal sealed class NavigationTransitionRuleTable |
| | | 15 | | { |
| | | 16 | | internal const long BaseRetainedBytes = 40L; |
| | 1 | 17 | | internal static readonly long RecordRetainedBytes = Unsafe.SizeOf<TraversalTransitionRule>(); |
| | | 18 | | private const long ArrayHeaderBytes = 24L; |
| | | 19 | | |
| | 1 | 20 | | internal static readonly NavigationTransitionRuleTable Empty = new( |
| | 1 | 21 | | Array.Empty<TraversalTransitionRule>(), |
| | 1 | 22 | | version: 0); |
| | | 23 | | |
| | | 24 | | private readonly TraversalTransitionRule[] _rules; |
| | | 25 | | |
| | 48 | 26 | | internal NavigationTransitionRuleTable( |
| | 48 | 27 | | TraversalTransitionRule[] rules, |
| | 48 | 28 | | long version) |
| | | 29 | | { |
| | 48 | 30 | | _rules = rules; |
| | 48 | 31 | | Version = version; |
| | 48 | 32 | | } |
| | | 33 | | |
| | 2962 | 34 | | internal int Count => _rules.Length; |
| | | 35 | | |
| | | 36 | | internal long Version { get; } |
| | | 37 | | |
| | 1623 | 38 | | internal TraversalTransitionRule this[int index] => _rules[index]; |
| | | 39 | | |
| | 918 | 40 | | internal long RetainedBytes => checked( |
| | 918 | 41 | | BaseRetainedBytes |
| | 918 | 42 | | + (_rules.Length == 0 |
| | 918 | 43 | | ? 0L |
| | 918 | 44 | | : ArrayHeaderBytes + ((long)_rules.Length * RecordRetainedBytes))); |
| | | 45 | | |
| | 961 | 46 | | internal int PersistentPageCount => _rules.Length == 0 ? 1 : 2; |
| | | 47 | | |
| | | 48 | | } |