| | | 1 | | using MemoryPack; |
| | | 2 | | using System; |
| | | 3 | | using System.Text.Json.Serialization; |
| | | 4 | | |
| | | 5 | | namespace SwiftCollections; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Represents the immutable state of a sparse set, containing the dense keys and associated values. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// This structure is typically used to serialize or inspect the contents of a sparse set. |
| | | 12 | | /// The arrays are guaranteed to be non-null, but may be empty if the set contains no elements. |
| | | 13 | | /// </remarks> |
| | | 14 | | /// <typeparam name="T">The type of values stored in the sparse set.</typeparam> |
| | | 15 | | [Serializable] |
| | | 16 | | [MemoryPackable] |
| | | 17 | | public readonly partial struct SwiftSparseSetState<T> |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Gets the collection of dense keys associated with this instance. |
| | | 21 | | /// </summary> |
| | | 22 | | [JsonInclude] |
| | | 23 | | [MemoryPackInclude] |
| | | 24 | | public readonly int[] DenseKeys; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets the array containing the dense values for this instance. |
| | | 28 | | /// </summary> |
| | | 29 | | [JsonInclude] |
| | | 30 | | [MemoryPackInclude] |
| | | 31 | | public readonly T[] DenseValues; |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Initializes a new instance of the SwiftSparseSetState class with the specified dense keys and values. |
| | | 35 | | /// </summary> |
| | | 36 | | /// <param name="denseKeys"> |
| | | 37 | | /// An array of integers representing the dense keys to initialize the set with. |
| | | 38 | | /// If null, an empty array is used. |
| | | 39 | | /// </param> |
| | | 40 | | /// <param name="denseValues"> |
| | | 41 | | /// An array of values of type T corresponding to the dense keys. |
| | | 42 | | /// If null, an empty array is used. |
| | | 43 | | /// </param> |
| | | 44 | | [JsonConstructor] |
| | | 45 | | [MemoryPackConstructor] |
| | | 46 | | public SwiftSparseSetState(int[] denseKeys, T[] denseValues) |
| | | 47 | | { |
| | 10 | 48 | | DenseKeys = denseKeys ?? Array.Empty<int>(); |
| | 10 | 49 | | DenseValues = denseValues ?? Array.Empty<T>(); |
| | 10 | 50 | | } |
| | | 51 | | } |