From a9b041a7e62f408e07d15cb7cf253d76919b6fa1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 29 Apr 2017 22:37:51 -0400 Subject: rework refresh queue --- MediaBrowser.Providers/Manager/IPriorityQueue.cs | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 MediaBrowser.Providers/Manager/IPriorityQueue.cs (limited to 'MediaBrowser.Providers/Manager/IPriorityQueue.cs') diff --git a/MediaBrowser.Providers/Manager/IPriorityQueue.cs b/MediaBrowser.Providers/Manager/IPriorityQueue.cs new file mode 100644 index 000000000..11f2c6214 --- /dev/null +++ b/MediaBrowser.Providers/Manager/IPriorityQueue.cs @@ -0,0 +1,59 @@ +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. + /// + TItem Dequeue(); + + /// + /// 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; } + } +} -- cgit v1.2.3