diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-04-29 22:45:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-04-29 22:45:28 -0400 |
| commit | 6cce89d22e37952a1c052d1d51089bc88fef6f1b (patch) | |
| tree | 35386f3e09af11dd898ba6e09d1340844926be22 /MediaBrowser.Providers/Manager/IPriorityQueue.cs | |
| parent | b7226b86674bde314d489a59ce65118d1f14fa37 (diff) | |
| parent | 7ef16a449ae044306227da00a83f5abe062fb893 (diff) | |
Merge pull request #2603 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Providers/Manager/IPriorityQueue.cs')
| -rw-r--r-- | MediaBrowser.Providers/Manager/IPriorityQueue.cs | 59 |
1 files changed, 59 insertions, 0 deletions
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 +{ + /// <summary> + /// 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. + /// </summary> + public interface IPriorityQueue<TItem, in TPriority> : IEnumerable<TItem> + where TPriority : IComparable<TPriority> + { + /// <summary> + /// 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. + /// </summary> + void Enqueue(TItem node, TPriority priority); + + /// <summary> + /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it. + /// </summary> + TItem Dequeue(); + + /// <summary> + /// Removes every node from the queue. + /// </summary> + void Clear(); + + /// <summary> + /// Returns whether the given node is in the queue. + /// </summary> + bool Contains(TItem node); + + /// <summary> + /// Removes a node from the queue. The node does not need to be the head of the queue. + /// </summary> + void Remove(TItem node); + + /// <summary> + /// Call this method to change the priority of a node. + /// </summary> + void UpdatePriority(TItem node, TPriority priority); + + /// <summary> + /// Returns the head of the queue, without removing it (use Dequeue() for that). + /// </summary> + TItem First { get; } + + /// <summary> + /// Returns the number of nodes in the queue. + /// </summary> + int Count { get; } + } +} |
