Interface IScyllaPriorityQueueItem
Optional interface for items that carry their own integer priority value, allowing them to be used directly with ScyllaPriorityQueue<T> without writing a custom IComparer<T>.
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public interface IScyllaPriorityQueueItem
Remarks
This interface exists solely to reduce boilerplate for the common case where an item type already exposes a meaningful integer priority. Instead of implementing a dedicated comparer class, implement this interface on the item type and construct the priority queue with Default as the comparer argument.
Implementing this interface does not automatically place an item into any collection. The interface is purely a data contract - it is only meaningful when the queue is constructed with a comparer that reads QueuePriority, such as ScyllaPriorityQueueItemComparer<T>.
The ordering semantics of QueuePriority depend on the ScyllaPriorityQueueOrder value passed to the queue:
- Min - items with a smaller QueuePriority value are dequeued first (e.g., 1 before 5).
- Max - items with a larger QueuePriority value are dequeued first (e.g., 5 before 1).
// 1. Implement the interface on your item type.
public class GameEvent : IScyllaPriorityQueueItem
{
public int QueuePriority { get; }
public string Name { get; }
public GameEvent(string name, int priority)
{
Name = name;
QueuePriority = priority;
}
}
// 2. Construct the queue with ScyllaPriorityQueueItemComparer<T>.Default.
// Min-heap: lower numbers dequeue first (higher urgency = lower number).
var queue = new ScyllaPriorityQueue<GameEvent>(
order: ScyllaPriorityQueueOrder.Min,
comparer: ScyllaPriorityQueueItemComparer<GameEvent>.Default);
queue.TryEnqueue(new GameEvent("LowPriority", 10));
queue.TryEnqueue(new GameEvent("HighPriority", 1));
queue.TryDequeue(out var next); // next.Name == "HighPriority"
Properties
QueuePriority
Gets the integer priority value that determines the relative ordering of this item within a ScyllaPriorityQueue<T> that uses ScyllaPriorityQueueItemComparer<T>.
Declaration
int QueuePriority { get; }
Property Value
| Type | Description |
|---|---|
| int | An integer representing the item's priority. The meaning of the value depends on the heap ordering:
There are no enforced constraints on the range of this value; the full int range is valid. Negative values are permitted and may represent the highest priority in a min-heap. |
Remarks
This property is read by Compare(T, T) on every comparison performed during heap maintenance (sift-up on enqueue, sift-down on dequeue). Implementations should ensure this property is inexpensive to read - a simple backing field is ideal. Avoid side effects or expensive computation inside the getter.