< 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: 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/SwiftBucketState.cs

#LineLine coverage
 1//=======================================================================
 2// SwiftBucketState.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 MemoryPack;
 9using System;
 10using System.Text.Json.Serialization;
 11
 12namespace SwiftCollections;
 13
 14/// <summary>
 15/// Represents the state of a bucket in a fast allocation pool, including the items, allocation status, free indices, an
 16/// </summary>
 17/// <remarks>
 18/// This struct is typically used to capture or transfer the current state of a bucket-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 bucket.</typeparam>
 23[Serializable]
 24[MemoryPackable]
 25public readonly partial struct SwiftBucketState<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 SwiftBucketState class with the specified items, allocation states, free indic
 57    /// </summary>
 58    /// <param name="items">The array of items contained in the bucket. Cannot be null; an empty array is used if null i
 59    /// <param name="allocated">
 60    /// An array indicating which items in the bucket 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 bucket.
 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 bucket at any point.</param>
 68    [JsonConstructor]
 69    [MemoryPackConstructor]
 70    public SwiftBucketState(T[] items, bool[] allocated, int[] freeIndices, int peakCount)
 71    {
 1072        Items = items ?? Array.Empty<T>();
 1073        Allocated = allocated ?? Array.Empty<bool>();
 1074        FreeIndices = freeIndices ?? Array.Empty<int>();
 1075        PeakCount = peakCount;
 1076    }
 77}