< Summary

Information
Class: SwiftCollections.SwiftTicketMapState<T>
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Serialization/State/SwiftTicketMapState.cs
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 96
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%88100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Serialization/State/SwiftTicketMapState.cs

#LineLine coverage
 1//=======================================================================
 2// SwiftTicketMapState.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
 8using System;
 9using System.Text.Json.Serialization;
 10using MemoryPack;
 11
 12namespace SwiftCollections;
 13
 14/// <summary>
 15/// Represents the immutable state of a generational map, including item storage, allocation status, generation tracking
 16/// </summary>
 17/// <remarks>
 18/// This struct is typically used to capture or transfer the complete state of a generational map for serialization, per
 19/// All arrays are expected to be of the same length, and the struct is designed for efficient value-type usage.
 20/// The state is read-only and does not provide mutation operations.</remarks>
 21/// <typeparam name="T">The type of elements stored in the map.</typeparam>
 22[Serializable]
 23[MemoryPackable]
 24public readonly partial struct SwiftTicketMapState<T>
 25{
 26    /// <summary>
 27    /// Gets the array of items contained in the collection.
 28    /// </summary>
 29    [JsonInclude]
 30    [MemoryPackInclude]
 31    public readonly T[] Items;
 32
 33    /// <summary>
 34    /// Indicates which items in the collection are currently allocated.
 35    /// </summary>
 36    [JsonInclude]
 37    [MemoryPackInclude]
 38    public readonly bool[] Allocated;
 39
 40    /// <summary>
 41    /// Gets the collection of generation values associated with this instance.
 42    /// </summary>
 43    [JsonInclude]
 44    [MemoryPackInclude]
 45    public readonly uint[] Generations;
 46
 47    /// <summary>
 48    /// Gets the collection of indices that are currently available for allocation.
 49    /// </summary>
 50    [JsonInclude]
 51    [MemoryPackInclude]
 52    public readonly int[] FreeIndices;
 53
 54    /// <summary>
 55    /// Gets the peak value recorded during the measurement period.
 56    /// </summary>
 57    [JsonInclude]
 58    [MemoryPackInclude]
 59    public readonly int Peak;
 60
 61    /// <summary>
 62    /// Initializes a new instance of the SwiftTicketMapState class with the specified items, allocation states,
 63    /// generation counters, free indices, and peak index.
 64    /// </summary>
 65    /// <param name="items">The array of items to be managed by the map. Cannot be null; an empty array is used if null 
 66    /// <param name="allocated">
 67    /// An array indicating which slots in the map are currently allocated.
 68    /// Each element corresponds to an item in the items array.
 69    /// Cannot be null; an empty array is used if null is provided.
 70    /// </param>
 71    /// <param name="generations">
 72    /// An array of generation counters for each slot in the map.
 73    /// Used to track the version or state of each item.
 74    /// Cannot be null; an empty array is used if null is provided.
 75    /// </param>
 76    /// <param name="freeIndices">
 77    /// An array of indices representing the free slots available for allocation.
 78    /// Cannot be null; an empty array is used if null is provided.
 79    /// </param>
 80    /// <param name="peak">The highest index that has been allocated in the map. Must be greater than or equal to zero.<
 81    [JsonConstructor]
 82    [MemoryPackConstructor]
 83    public SwiftTicketMapState(
 84        T[] items,
 85        bool[] allocated,
 86        uint[] generations,
 87        int[] freeIndices,
 88        int peak)
 89    {
 2090        Items = items ?? Array.Empty<T>();
 2091        Allocated = allocated ?? Array.Empty<bool>();
 2092        Generations = generations ?? Array.Empty<uint>();
 2093        FreeIndices = freeIndices ?? Array.Empty<int>();
 2094        Peak = peak;
 2095    }
 96}