using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Priority_Queue { /// /// Credit: https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp /// The IPriorityQueue interface. This is mainly here for purists, and in case I decide to add more implementations later. /// For speed purposes, it is actually recommended that you *don't* access the priority queue through this interface, since the JIT can /// (theoretically?) optimize method calls from concrete-types slightly better. /// public interface IPriorityQueue : IEnumerable where TPriority : IComparable { /// /// Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken by first-in-first-out. /// See implementation for how duplicates are handled. /// void Enqueue(TItem node, TPriority priority); /// /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it. /// bool TryDequeue(out TItem item); /// /// Removes every node from the queue. /// void Clear(); /// /// Returns whether the given node is in the queue. /// bool Contains(TItem node); /// /// Removes a node from the queue. The node does not need to be the head of the queue. /// void Remove(TItem node); /// /// Call this method to change the priority of a node. /// void UpdatePriority(TItem node, TPriority priority); /// /// Returns the head of the queue, without removing it (use Dequeue() for that). /// TItem First { get; } /// /// Returns the number of nodes in the queue. /// int Count { get; } } }