diff options
Diffstat (limited to 'MediaBrowser.Providers/Manager/GenericPriorityQueue.cs')
| -rw-r--r-- | MediaBrowser.Providers/Manager/GenericPriorityQueue.cs | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/MediaBrowser.Providers/Manager/GenericPriorityQueue.cs b/MediaBrowser.Providers/Manager/GenericPriorityQueue.cs index 0e6c07357..b87f688e1 100644 --- a/MediaBrowser.Providers/Manager/GenericPriorityQueue.cs +++ b/MediaBrowser.Providers/Manager/GenericPriorityQueue.cs @@ -1,9 +1,7 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace Priority_Queue { @@ -43,25 +41,13 @@ namespace Priority_Queue /// Returns the number of nodes in the queue. /// O(1) /// </summary> - public int Count - { - get - { - return _numNodes; - } - } + public int Count => _numNodes; /// <summary> /// Returns the maximum number of items that can be enqueued at once in this queue. Once you hit this number (ie. once Count == MaxSize), /// attempting to enqueue another item will cause undefined behavior. O(1) /// </summary> - public int MaxSize - { - get - { - return _nodes.Length - 1; - } - } + public int MaxSize => _nodes.Length - 1; /// <summary> /// Removes every node from the queue. @@ -83,7 +69,7 @@ namespace Priority_Queue #if DEBUG if (node == null) { - throw new ArgumentNullException("node"); + throw new ArgumentNullException(nameof(node)); } if (node.QueueIndex < 0 || node.QueueIndex >= _nodes.Length) { @@ -106,7 +92,7 @@ namespace Priority_Queue #if DEBUG if (node == null) { - throw new ArgumentNullException("node"); + throw new ArgumentNullException(nameof(node)); } if (_numNodes >= _nodes.Length - 1) { @@ -146,7 +132,7 @@ namespace Priority_Queue int parent = node.QueueIndex / 2; while (parent >= 1) { - TItem parentNode = _nodes[parent]; + var parentNode = _nodes[parent]; if (HasHigherPriority(parentNode, node)) break; @@ -177,7 +163,7 @@ namespace Priority_Queue break; } - TItem childLeft = _nodes[childLeftIndex]; + var childLeft = _nodes[childLeftIndex]; if (HasHigherPriority(childLeft, newParent)) { newParent = childLeft; @@ -187,7 +173,7 @@ namespace Priority_Queue int childRightIndex = childLeftIndex + 1; if (childRightIndex <= _numNodes) { - TItem childRight = _nodes[childRightIndex]; + var childRight = _nodes[childRightIndex]; if (HasHigherPriority(childRight, newParent)) { newParent = childRight; @@ -248,7 +234,7 @@ namespace Priority_Queue } #endif - TItem returnMe = _nodes[1]; + var returnMe = _nodes[1]; Remove(returnMe); item = returnMe; return true; @@ -303,7 +289,7 @@ namespace Priority_Queue } /// <summary> - /// This method must be called on a node every time its priority changes while it is in the queue. + /// This method must be called on a node every time its priority changes while it is in the queue. /// <b>Forgetting to call this method will result in a corrupted queue!</b> /// Calling this method on a node not in the queue results in undefined behavior /// O(log n) @@ -314,7 +300,7 @@ namespace Priority_Queue #if DEBUG if (node == null) { - throw new ArgumentNullException("node"); + throw new ArgumentNullException(nameof(node)); } if (!Contains(node)) { @@ -330,7 +316,7 @@ namespace Priority_Queue { //Bubble the updated node up or down as appropriate int parentIndex = node.QueueIndex / 2; - TItem parentNode = _nodes[parentIndex]; + var parentNode = _nodes[parentIndex]; if (parentIndex > 0 && HasHigherPriority(node, parentNode)) { @@ -344,7 +330,7 @@ namespace Priority_Queue } /// <summary> - /// Removes a node from the queue. The node does not need to be the head of the queue. + /// Removes a node from the queue. The node does not need to be the head of the queue. /// If the node is not in the queue, the result is undefined. If unsure, check Contains() first /// O(log n) /// </summary> @@ -353,7 +339,7 @@ namespace Priority_Queue #if DEBUG if (node == null) { - throw new ArgumentNullException("node"); + throw new ArgumentNullException(nameof(node)); } if (!Contains(node)) { @@ -370,7 +356,7 @@ namespace Priority_Queue } //Swap the node with the last node - TItem formerLastNode = _nodes[_numNodes]; + var formerLastNode = _nodes[_numNodes]; Swap(node, formerLastNode); _nodes[_numNodes] = null; _numNodes--; |
