| | | 1 | | using MemoryPack; |
| | | 2 | | using System; |
| | | 3 | | using System.Text.Json.Serialization; |
| | | 4 | | |
| | | 5 | | namespace SwiftCollections; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Represents the state of a bucket in a fast allocation pool, including the items, allocation status, free indices, an |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// This struct is typically used to capture or transfer the current state of a bucket-based memory pool. |
| | | 12 | | /// It provides direct access to the underlying arrays representing the items, their allocation status, and the indices |
| | | 13 | | /// The struct is serializable and designed for efficient state management in high-performance scenarios. |
| | | 14 | | /// </remarks> |
| | | 15 | | /// <typeparam name="T">The type of items stored in the bucket.</typeparam> |
| | | 16 | | [Serializable] |
| | | 17 | | [MemoryPackable] |
| | | 18 | | public readonly partial struct SwiftBucketState<T> |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets the array of items contained in the collection. |
| | | 22 | | /// </summary> |
| | | 23 | | [JsonInclude] |
| | | 24 | | [MemoryPackInclude] |
| | | 25 | | public readonly T[] Items; |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Indicates which items in the collection are currently allocated. |
| | | 29 | | /// </summary> |
| | | 30 | | [JsonInclude] |
| | | 31 | | [MemoryPackInclude] |
| | | 32 | | public readonly bool[] Allocated; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets the collection of indices that are currently available for allocation. |
| | | 36 | | /// </summary> |
| | | 37 | | [JsonInclude] |
| | | 38 | | [MemoryPackInclude] |
| | | 39 | | public readonly int[] FreeIndices; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Gets the maximum number of peaks detected or recorded. |
| | | 43 | | /// </summary> |
| | | 44 | | [JsonInclude] |
| | | 45 | | [MemoryPackInclude] |
| | | 46 | | public readonly int PeakCount; |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Initializes a new instance of the SwiftBucketState class with the specified items, allocation states, free indic |
| | | 50 | | /// </summary> |
| | | 51 | | /// <param name="items">The array of items contained in the bucket. Cannot be null; an empty array is used if null i |
| | | 52 | | /// <param name="allocated"> |
| | | 53 | | /// An array indicating which items in the bucket are currently allocated. |
| | | 54 | | /// Cannot be null; an empty array is used if null is provided. |
| | | 55 | | /// </param> |
| | | 56 | | /// <param name="freeIndices"> |
| | | 57 | | /// An array of indices representing the positions of free items in the bucket. |
| | | 58 | | /// Cannot be null; an empty array is used if null is provided. |
| | | 59 | | /// </param> |
| | | 60 | | /// <param name="peakCount">The highest number of items that have been allocated in the bucket at any point.</param> |
| | | 61 | | [JsonConstructor] |
| | | 62 | | [MemoryPackConstructor] |
| | | 63 | | public SwiftBucketState(T[] items, bool[] allocated, int[] freeIndices, int peakCount) |
| | | 64 | | { |
| | 8 | 65 | | Items = items ?? Array.Empty<T>(); |
| | 8 | 66 | | Allocated = allocated ?? Array.Empty<bool>(); |
| | 8 | 67 | | FreeIndices = freeIndices ?? Array.Empty<int>(); |
| | 8 | 68 | | PeakCount = peakCount; |
| | 8 | 69 | | } |
| | | 70 | | } |