< Summary

Information
Class: SwiftCollections.SwiftSlotMapState<T>
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Serialization/State/SwiftSlotMapState.cs
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 77
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%66100%

File(s)

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

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