< Summary

Information
Class: MoreStructures.PriorityQueues.PrioritizedItem<T>
Assembly: MoreStructures
File(s): /home/runner/work/MoreStructures/MoreStructures/MoreStructures/PriorityQueues/PrioritizedItem.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 53
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 Cyclomatic complexity Line coverage
get_Item()100%1100%
.ctor(...)100%1100%
CompareTo(...)100%4100%

File(s)

/home/runner/work/MoreStructures/MoreStructures/MoreStructures/PriorityQueues/PrioritizedItem.cs

#LineLine coverage
 1namespace MoreStructures.PriorityQueues;
 2
 3/// <summary>
 4/// An item of type <typeparamref name="T"/> with a priority and a "push timestamp" assigned to it.
 5/// </summary>
 6/// <typeparam name="T">The type of the <paramref name="Item"/>.</typeparam>
 7/// <param name="Item">The item.</param>
 8/// <param name="Priority">The <see cref="int"/> defining the priority of the <paramref name="Item"/>.</param>
 9/// <param name="PushTimestamp">
 10/// A strictly monotonic increasing <see cref="int"/>, uniquely identifying an insertion of the <paramref name="Item"/>
 11/// in the queue via <see cref="IPriorityQueue{T}.Push(T, int)"/>. To be considered as offsets of
 12/// <paramref name="PushTimestampEra"/>.
 13/// </param>
 14/// <param name="PushTimestampEra">
 15/// The base for <paramref name="PushTimestamp"/>.
 16/// <br/>
 17/// Same or equivalent <paramref name="PushTimestampEra"/> and same <paramref name="PushTimestamp"/> correspond to same
 18/// actual timestamps.
 19/// <br/>
 20/// Timestamps in different eras can never be equal (i.e. there is strict order of timestamps between eras).
 21/// </param>
 506379522public record struct PrioritizedItem<T>(T Item, int Priority, int PushTimestamp, PushTimestampEra PushTimestampEra)
 23    : IComparable<PrioritizedItem<T>>
 24{
 25    /// <inheritdoc cref="PrioritizedItem{T}"/>
 26    public PrioritizedItem(T Item, int Priority, int PushTimestamp) :
 2974727        this(Item, Priority, PushTimestamp, new(0))
 5949428    { }
 29
 30    /// <inheritdoc path="//*[not(self::remarks)]"/>
 31    /// <remarks>
 32    /// Comparison is made by <see cref="Priority"/> first: bigger <see cref="Priority"/> determines bigger instance.
 33    /// <br/>
 34    /// If the two instances have the same <see cref="Priority"/>, comparison is made by <see cref="PushTimestampEra"/>
 35    /// values: smaller <see cref="PushTimestampEra"/> determines higher priority instance.
 36    /// <br/>
 37    /// If the two instances have the same <see cref="PushTimestampEra"/>, comparison is made by
 38    /// <see cref="PushTimestamp"/>: smaller <see cref="PushTimestamp"/> determines higher priority instance.
 39    /// <br/>
 40    /// If <see cref="Priority"/>, <see cref="PushTimestampEra"/> and <see cref="PushTimestamp"/> are the same,
 41    /// returned value is 0.
 42    /// </remarks>
 43    public int CompareTo(PrioritizedItem<T> other)
 123440444    {
 123440445        var priorityDifference = Priority - other.Priority;
 123440446        if (priorityDifference != 0)
 94534947            return priorityDifference;
 28905548        var eraDifference = -PushTimestampEra.Era + other.PushTimestampEra.Era;
 28905549        if (eraDifference != 0)
 499850            return eraDifference;
 28405751        return -PushTimestamp + other.PushTimestamp;
 123440452    }
 53}