Class OrderedPriorityQueue<TPriority, TValue>
- Namespace
- Ecng.Collections
- Assembly
- Ecng.Collections.dll
Represents a priority queue that sorts elements based on a specified key.
[Obsolete("Use PriorityQueue.")]
public class OrderedPriorityQueue<TPriority, TValue> : ICollection<KeyValuePair<TPriority, TValue>>, IEnumerable<KeyValuePair<TPriority, TValue>>, IEnumerable, IQueue<KeyValuePair<TPriority, TValue>>
Type Parameters
TPriority
The type used to determine the sort order of elements.
TValue
The type of the values stored in the queue.
- Inheritance
-
OrderedPriorityQueue<TPriority, TValue>
- Implements
-
ICollection<KeyValuePair<TPriority, TValue>>IEnumerable<KeyValuePair<TPriority, TValue>>IQueue<KeyValuePair<TPriority, TValue>>
- Inherited Members
- Extension Methods
Constructors
OrderedPriorityQueue()
Initializes a new instance of the OrderedPriorityQueue<TPriority, TValue> class.
public OrderedPriorityQueue()
OrderedPriorityQueue(IComparer<TPriority>)
Initializes a new instance of the OrderedPriorityQueue<TPriority, TValue> class using the specified comparer.
public OrderedPriorityQueue(IComparer<TPriority> comparer)
Parameters
comparer
IComparer<TPriority>The comparer used to sort the keys.
Properties
Count
Gets number of elements in the priority queue
public int Count { get; }
Property Value
IsEmpty
Gets whether priority queue is empty
public bool IsEmpty { get; }
Property Value
IsReadOnly
Gets a value indicating whether the collection is read-only.
public bool IsReadOnly { get; }
Property Value
Remarks
For priority queue this property returns false
.
Methods
Add(KeyValuePair<TPriority, TValue>)
Enqueus element into priority queue
public void Add(KeyValuePair<TPriority, TValue> item)
Parameters
item
KeyValuePair<TPriority, TValue>element to add
Clear()
Clears the collection
public void Clear()
Contains(KeyValuePair<TPriority, TValue>)
Determines whether the priority queue contains a specific element
public bool Contains(KeyValuePair<TPriority, TValue> item)
Parameters
item
KeyValuePair<TPriority, TValue>The object to locate in the priority queue
Returns
- bool
true
if item is found in the priority queue; otherwise,false.
CopyTo(KeyValuePair<TPriority, TValue>[], int)
Copies the elements of the priority queue to an Array, starting at a particular Array index.
public void CopyTo(KeyValuePair<TPriority, TValue>[] array, int arrayIndex)
Parameters
array
KeyValuePair<TPriority, TValue>[]The one-dimensional Array that is the destination of the elements copied from the priority queue. The Array must have zero-based indexing.
arrayIndex
intThe zero-based index in array at which copying begins.
Remarks
It is not guaranteed that items will be copied in the sorted order.
Dequeue()
Dequeues element with minimum priority and return its priority and value as KeyValuePair<TKey, TValue>
public KeyValuePair<TPriority, TValue> Dequeue()
Returns
- KeyValuePair<TPriority, TValue>
priority and value of the dequeued element
Remarks
Method throws InvalidOperationException if priority queue is empty
DequeueValue()
Dequeues element with minimum priority and return its priority and value as KeyValuePair<TKey, TValue>
public TValue DequeueValue()
Returns
- TValue
priority and value of the dequeued element
Remarks
Method throws InvalidOperationException if priority queue is empty
Enqueue(TPriority, TValue)
Enqueues element into priority queue
public void Enqueue(TPriority priority, TValue value)
Parameters
priority
TPriorityelement priority
value
TValueelement value
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<KeyValuePair<TPriority, TValue>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<TPriority, TValue>>
Enumerator
Remarks
Returned enumerator does not iterate elements in sorted order.
Peek()
Returns priority and value of the element with minimun priority, without removing it from the queue
public KeyValuePair<TPriority, TValue> Peek()
Returns
- KeyValuePair<TPriority, TValue>
priority and value of the element with minimum priority
Remarks
Method throws InvalidOperationException if priority queue is empty
PeekValue()
Returns priority and value of the element with minimun priority, without removing it from the queue
public TValue PeekValue()
Returns
- TValue
priority and value of the element with minimum priority
Remarks
Method throws InvalidOperationException if priority queue is empty
Remove(KeyValuePair<TPriority, TValue>)
Removes the first occurrence of a specific object from the priority queue.
public bool Remove(KeyValuePair<TPriority, TValue> item)
Parameters
item
KeyValuePair<TPriority, TValue>The object to remove from the ICollection<T>.
Returns
- bool
true
if item was successfully removed from the priority queue. This method returns false if item is not found in the collection.
RemoveRange(IEnumerable<KeyValuePair<TPriority, TValue>>)
Removes the range of elements from the priority queue.
public void RemoveRange(IEnumerable<KeyValuePair<TPriority, TValue>> items)
Parameters
items
IEnumerable<KeyValuePair<TPriority, TValue>>The range of elements to remove from the priority queue.