< Summary

Information
Class: SwiftCollections.SwiftBucketState<T>
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Serialization/State/SwiftBucketState.cs
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 70
Line coverage: 100%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)66.66%66100%

File(s)

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

#LineLine coverage
 1using MemoryPack;
 2using System;
 3using System.Text.Json.Serialization;
 4
 5namespace 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]
 18public 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    {
 865        Items = items ?? Array.Empty<T>();
 866        Allocated = allocated ?? Array.Empty<bool>();
 867        FreeIndices = freeIndices ?? Array.Empty<int>();
 868        PeakCount = peakCount;
 869    }
 70}