< 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: 69
Line coverage: 100%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
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(...)50%22100%
Equals(...)50%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
 1using System;
 2
 3namespace SwiftCollections;
 4
 5/// <summary>
 6/// Represents a value type handle that uniquely identifies an object or resource by index and generation.
 7/// </summary>
 8/// <remarks>
 9/// A <see cref="SwiftHandle"/> consists of an integer index and an unsigned generation value.
 10/// This combination helps detect stale or invalid references when resources are recycled.
 11///</remarks>
 12public readonly struct SwiftHandle : IEquatable<SwiftHandle>
 13{
 14    /// <summary>
 15    /// Gets the zero-based index associated with this instance.
 16    /// </summary>
 17    public readonly int Index;
 18
 19    /// <summary>
 20    /// Gets the generation number associated with this instance.
 21    /// </summary>
 22    public readonly uint Generation;
 23
 24    /// <summary>
 25    /// Initializes a new instance of the SwiftHandle class with the specified index and generation values.
 26    /// </summary>
 27    /// <param name="index">
 28    /// The zero-based index that identifies the handle.
 29    /// Must be greater than or equal to 0.
 30    /// </param>
 31    /// <param name="generation">
 32    /// The generation value associated with the handle.
 33    /// Used to distinguish between different versions of the same index.
 34    /// </param>
 35    public SwiftHandle(int index, uint generation)
 36    {
 35037        Index = index;
 35038        Generation = generation;
 35039    }
 40
 41    /// <inheritdoc/>
 42    public bool Equals(SwiftHandle other)
 443        => Index == other.Index && Generation == other.Generation;
 44
 45    /// <inheritdoc/>
 46    public override bool Equals(object? obj)
 147        => obj is SwiftHandle h && Equals(h);
 48
 49    /// <inheritdoc/>
 50    public override int GetHashCode()
 251        => HashCode.Combine(Index, Generation);
 52
 53    /// <summary>
 54    /// Returns a string that represents the current handle, including its index and generation values.
 55    /// </summary>
 56    /// <returns>A string in the format "Handle({Index}:{Generation})" that identifies the handle by its index and gener
 57    public override string ToString()
 158        => $"Handle({Index}:{Generation})";
 59
 60    /// <summary>
 61    /// Determines whether two SwiftHandle instances are equal.
 62    /// </summary>
 263    public static bool operator ==(SwiftHandle left, SwiftHandle right) => left.Equals(right);
 64
 65    /// <summary>
 66    /// Determines whether two SwiftHandle instances are not equal.
 67    /// </summary>
 168    public static bool operator !=(SwiftHandle left, SwiftHandle right) => !(left == right);
 69}