< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

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

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