New to Telerik UI for WPFStart a free 30-day trial

Priority queue implementation based on a RedBlackTreeList<TKey, TValue>.

Definition

Namespace:Telerik.Windows.Diagrams.Core

Assembly:Telerik.Windows.Diagrams.Core.dll

Type Parameters:

TValue

The data type of the value.

TPriority

The data type of the priority indicator.

Syntax:

C#
public sealed class PriorityQueue<TValue, TPriority> : ICollection<TValue>, IEnumerable<TValue>, IEnumerable

Inheritance: objectPriorityQueue<TValue, TPriority>

Implements: ICollection<TValue>IEnumerableIEnumerable<TValue>

Constructors

Initializes a new instance of the PriorityQueue<TValue, TPriority> class.

C#
public PriorityQueue(OrderType queueType, Comparison<TPriority> comparison)
Parameters:queueTypeOrderType

Type of the queue.

comparisonComparison<TPriority>

The comparison.

Initializes a new instance of the PriorityQueue<TValue, TPriority> class.

C#
public PriorityQueue(OrderType queueType, IComparer<TPriority> comparer)
Parameters:queueTypeOrderType

Type of the queue.

comparerIComparer<TPriority>

The comparer.

Initializes a new instance of the PriorityQueue<TValue, TPriority> class.

C#
public PriorityQueue(OrderType queueType = OrderType.Descending)
Parameters:queueTypeOrderType

Type of the queue.

Properties

Gets the number of elements still in the queue.

C#
public int Count { get; }

Implements: ICollection<TValue>.Count

Gets or sets the default priority when an item is added.

C#
public TPriority DefaultPriority { get; set; }
Property Value:

The default priority.

Remarks:

The default value is zero if not set.

Gets false since this queue is never read-only.

C#
public bool IsReadOnly { get; }
Property Value:

false.

Implements: ICollection<TValue>.IsReadOnly

Methods

Adds the specified item to the queue.

C#
public void Add(TValue item)
Parameters:itemTValue

The item.

Implements: ICollection<TValue>.Add(TValue)

Adds the specified items to the priority queue with the specified priority.

C#
public void AddPriorityGroup(IEnumerable<TValue> items, TPriority priority)
Parameters:itemsIEnumerable<TValue>

The items.

priorityTPriority

The priority.

Exceptions:

ArgumentNullException

items is a null reference (Nothing in Visual Basic).

Clears this queue of all its items..

C#
public void Clear()

Implements: ICollection<TValue>.Clear()

Returns whether the given item is present in the queue.

C#
public bool Contains(TValue item)
Parameters:itemTValue

The item.

Returns:

bool

true if the queue contains the given item; otherwise, false.

Implements: ICollection<TValue>.Contains(TValue)

Copies the content of the queue to the given array.

C#
public void CopyTo(TValue[] array, int arrayIndex)
Parameters:arrayTValue[]

The array.

arrayIndexint

Index of the array.

Implements: ICollection<TValue>.CopyTo(TValue[], int)

Dequeues the item from the head of the queue.

C#
public TValue Dequeue(out TPriority priority)
Parameters:priorityTPriority

The priority of the item to dequeue.

Returns:

TValue

The item at the head of the queue.

Exceptions:

InvalidOperationException

The PriorityQueue<TValue, TPriority> is empty.

Enqueues the specified item.

C#
public void Enqueue(TValue item, TPriority priority)
Parameters:itemTValue

The item.

priorityTPriority

The priority.

Enqueues the specified item.

C#
public void Enqueue(TValue item)
Parameters:itemTValue

The item.

Returns an enumerator that iterates through the collection.

C#
public IEnumerator<TValue> GetEnumerator()
Returns:

IEnumerator<TValue>

A IEnumerator<T> that can be used to iterate through the collection.

Implements: IEnumerable<TValue>.GetEnumerator()

Returns an enumerator that iterates through the keys in the collection.

C#
public IEnumerator<KeyValuePair<TPriority, TValue>> GetKeyEnumerator()
Returns:

IEnumerator<KeyValuePair<TPriority, TValue>>

A IEnumerator<T> that can be used to iterate through the keys in the collection.

Removes the items with the specified priority.

C#
public IList<TValue> GetPriorityGroup(TPriority priority)
Parameters:priorityTPriority

The priority.

Returns:

IList<TValue>

The items with the specified priority.

Peeks at the item in the front of the queue, without removing it.

C#
public TValue Peek()
Returns:

TValue

The item at the front of the queue.

Peeks at the item in the front of the queue, without removing it.

C#
public TValue Peek(out TPriority priority)
Parameters:priorityTPriority

The priority of the item.

Returns:

TValue

The item at the front of the queue.

Dequeues the item at the front of the queue.

C#
public TValue Pop()
Returns:

TValue

The item at the front of the queue.

Adds an item to the ICollection<T>.

C#
public void Push(TValue item, TPriority priority)
Parameters:itemTValue

The object to add to the ICollection<T>.

priorityTPriority

The priority of the item.

Pushes the specified item in the queue.

C#
public void Push(TValue item)
Parameters:itemTValue

The item.

Removes the first occurrence of the specified item from the property queue.

C#
public bool Remove(TValue item, out TPriority priority)
Parameters:itemTValue

The item to remove.

priorityTPriority

The priority associated with the item.

Returns:

bool

true if the item exists in the PriorityQueue<TValue, TPriority> and has been removed; otherwise false.

Removes the specified item from this queue.

C#
public bool Remove(TValue item)
Parameters:itemTValue

The item.

Returns:

bool

Implements: ICollection<TValue>.Remove(TValue)

Removes the items with the specified priority.

C#
public bool RemovePriorityGroup(TPriority priority)
Parameters:priorityTPriority

The priority.

Returns:

bool

true if the priority exists in the PriorityQueue<TValue, TPriority> and has been removed; otherwise false.