< Summary

Information
Class: SwiftCollections.SwiftHandle
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Collection/Support/SwiftHandle.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 76
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%11100%
Equals(...)100%22100%
Equals(...)100%22100%
GetHashCode()100%11100%
ToString()100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Collection/Support/SwiftHandle.cs

#LineLine coverage
 1//=======================================================================
 2// SwiftHandle.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;
 9
 10namespace SwiftCollections;
 11
 12/// <summary>
 13/// Represents a value type handle that uniquely identifies an object or resource by index and generation.
 14/// </summary>
 15/// <remarks>
 16/// A <see cref="SwiftHandle"/> consists of an integer index and an unsigned generation value.
 17/// This combination helps detect stale or invalid references when resources are recycled.
 18///</remarks>
 19public readonly struct SwiftHandle : IEquatable<SwiftHandle>
 20{
 21    /// <summary>
 22    /// Gets the zero-based index associated with this instance.
 23    /// </summary>
 24    public readonly int Index;
 25
 26    /// <summary>
 27    /// Gets the generation number associated with this instance.
 28    /// </summary>
 29    public readonly uint Generation;
 30
 31    /// <summary>
 32    /// Initializes a new instance of the SwiftHandle class with the specified index and generation values.
 33    /// </summary>
 34    /// <param name="index">
 35    /// The zero-based index that identifies the handle.
 36    /// Must be greater than or equal to 0.
 37    /// </param>
 38    /// <param name="generation">
 39    /// The generation value associated with the handle.
 40    /// Used to distinguish between different versions of the same index.
 41    /// </param>
 42    public SwiftHandle(int index, uint generation)
 43    {
 36344        Index = index;
 36345        Generation = generation;
 36346    }
 47
 48    /// <inheritdoc/>
 49    public bool Equals(SwiftHandle other)
 550        => Index == other.Index && Generation == other.Generation;
 51
 52    /// <inheritdoc/>
 53    public override bool Equals(object? obj)
 254        => obj is SwiftHandle h && Equals(h);
 55
 56    /// <inheritdoc/>
 57    public override int GetHashCode()
 258        => HashCode.Combine(Index, Generation);
 59
 60    /// <summary>
 61    /// Returns a string that represents the current handle, including its index and generation values.
 62    /// </summary>
 63    /// <returns>A string in the format "Handle({Index}:{Generation})" that identifies the handle by its index and gener
 64    public override string ToString()
 165        => $"Handle({Index}:{Generation})";
 66
 67    /// <summary>
 68    /// Determines whether two SwiftHandle instances are equal.
 69    /// </summary>
 270    public static bool operator ==(SwiftHandle left, SwiftHandle right) => left.Equals(right);
 71
 72    /// <summary>
 73    /// Determines whether two SwiftHandle instances are not equal.
 74    /// </summary>
 175    public static bool operator !=(SwiftHandle left, SwiftHandle right) => !(left == right);
 76}