< Summary

Information
Class: SwiftCollections.SwiftTicket
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Collection/Support/SwiftTicket.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 77
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/SwiftTicket.cs

#LineLine coverage
 1//=======================================================================
 2// SwiftTicket.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/// Identifies an allocation in its originating ticket map by index and generation.
 14/// </summary>
 15/// <remarks>
 16/// A <see cref="SwiftTicket"/> consists of an integer index and an unsigned generation value.
 17/// This combination helps detect stale references when slots are reused. Tickets carry no collection identity;
 18/// use them only with their originating map. Generation counters are finite.
 19///</remarks>
 20public readonly struct SwiftTicket : IEquatable<SwiftTicket>
 21{
 22    /// <summary>
 23    /// Gets the zero-based index associated with this instance.
 24    /// </summary>
 25    public readonly int Index;
 26
 27    /// <summary>
 28    /// Gets the generation number associated with this instance.
 29    /// </summary>
 30    public readonly uint Generation;
 31
 32    /// <summary>
 33    /// Initializes a new instance of the SwiftTicket class with the specified index and generation values.
 34    /// </summary>
 35    /// <param name="index">
 36    /// The zero-based index that identifies the ticket.
 37    /// Must be greater than or equal to 0.
 38    /// </param>
 39    /// <param name="generation">
 40    /// The generation value associated with the ticket.
 41    /// Used to distinguish between different versions of the same index.
 42    /// </param>
 43    public SwiftTicket(int index, uint generation)
 44    {
 62045        Index = index;
 62046        Generation = generation;
 62047    }
 48
 49    /// <inheritdoc/>
 50    public bool Equals(SwiftTicket other)
 2751        => Index == other.Index && Generation == other.Generation;
 52
 53    /// <inheritdoc/>
 54    public override bool Equals(object? obj)
 255        => obj is SwiftTicket h && Equals(h);
 56
 57    /// <inheritdoc/>
 58    public override int GetHashCode()
 259        => HashCode.Combine(Index, Generation);
 60
 61    /// <summary>
 62    /// Returns a string that represents the current ticket, including its index and generation values.
 63    /// </summary>
 64    /// <returns>A string in the format "Ticket({Index}:{Generation})" that identifies the ticket by its index and gener
 65    public override string ToString()
 166        => $"Ticket({Index}:{Generation})";
 67
 68    /// <summary>
 69    /// Determines whether two SwiftTicket instances are equal.
 70    /// </summary>
 271    public static bool operator ==(SwiftTicket left, SwiftTicket right) => left.Equals(right);
 72
 73    /// <summary>
 74    /// Determines whether two SwiftTicket instances are not equal.
 75    /// </summary>
 176    public static bool operator !=(SwiftTicket left, SwiftTicket right) => !(left == right);
 77}