Class
PriorityQueue<TValue, TPriority>

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:

cs-api-definition
[SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
public sealed class PriorityQueue<TValue, TPriority> : ICollection<TValue>, IEnumerable<TValue>, IEnumerable

Inheritance: objectPriorityQueue<TValue, TPriority>

Implements: ICollection<TValue>IEnumerableIEnumerable<TValue>

Constructors

PriorityQueue(OrderType)

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

Declaration

cs-api-definition
public PriorityQueue(OrderType queueType = OrderType.Descending)

Parameters

queueType

OrderType

Type of the queue.

PriorityQueue(OrderType, Comparison<TPriority>)

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

Declaration

cs-api-definition
public PriorityQueue(OrderType queueType, Comparison<TPriority> comparison)

Parameters

queueType

OrderType

Type of the queue.

comparison

Comparison<TPriority>

The comparison.

PriorityQueue(OrderType, IComparer<TPriority>)

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

Declaration

cs-api-definition
public PriorityQueue(OrderType queueType, IComparer<TPriority> comparer)

Parameters

queueType

OrderType

Type of the queue.

comparer

IComparer<TPriority>

The comparer.

Properties

Count

Gets the number of elements still in the queue.

Declaration

cs-api-definition
public int Count { get; }

Property Value

int

Implements ICollection<TValue>.Count

DefaultPriority

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

Declaration

cs-api-definition
public TPriority DefaultPriority { get; set; }

Property Value

TPriority

The default priority.

Remarks

The default value is zero if not set.

IsReadOnly

Gets false since this queue is never read-only.

Declaration

cs-api-definition
public bool IsReadOnly { get; }

Property Value

bool

false.

Implements ICollection<TValue>.IsReadOnly

Methods

Add(TValue)

Adds the specified item to the queue.

Declaration

cs-api-definition
public void Add(TValue item)

Parameters

item

TValue

The item.

Implements ICollection<TValue>.Add(TValue)

AddPriorityGroup(IEnumerable<TValue>, TPriority)

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

Declaration

cs-api-definition
public void AddPriorityGroup(IEnumerable<TValue> items, TPriority priority)

Parameters

items

IEnumerable<TValue>

The items.

priority

TPriority

The priority.

Exceptions

ArgumentNullException

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

Clear()

Clears this queue of all its items..

Declaration

cs-api-definition
public void Clear()

Implements ICollection<TValue>.Clear()

Contains(TValue)

Returns whether the given item is present in the queue.

Declaration

cs-api-definition
public bool Contains(TValue item)

Parameters

item

TValue

The item.

Returns

bool

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

Implements ICollection<TValue>.Contains(TValue)

CopyTo(TValue[], int)

Copies the content of the queue to the given array.

Declaration

cs-api-definition
public void CopyTo(TValue[] array, int arrayIndex)

Parameters

array

TValue[]

The array.

arrayIndex

int

Index of the array.

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

Dequeue(out TPriority)

Dequeues the item from the head of the queue.

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")]
public TValue Dequeue(out TPriority priority)

Parameters

priority

TPriority

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.

Enqueue(TValue)

Enqueues the specified item.

Declaration

cs-api-definition
public void Enqueue(TValue item)

Parameters

item

TValue

The item.

Enqueue(TValue, TPriority)

Enqueues the specified item.

Declaration

cs-api-definition
public void Enqueue(TValue item, TPriority priority)

Parameters

item

TValue

The item.

priority

TPriority

The priority.

GetEnumerator()

Returns an enumerator that iterates through the collection.

Declaration

cs-api-definition
public IEnumerator<TValue> GetEnumerator()

Returns

IEnumerator<TValue>

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

Implements IEnumerable<TValue>.GetEnumerator()

GetKeyEnumerator()

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

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
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.

GetPriorityGroup(TPriority)

Removes the items with the specified priority.

Declaration

cs-api-definition
public IList<TValue> GetPriorityGroup(TPriority priority)

Parameters

priority

TPriority

The priority.

Returns

IList<TValue>

The items with the specified priority.

Peek()

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

Declaration

cs-api-definition
public TValue Peek()

Returns

TValue

The item at the front of the queue.

Peek(out TPriority)

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

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")]
public TValue Peek(out TPriority priority)

Parameters

priority

TPriority

The priority of the item.

Returns

TValue

The item at the front of the queue.

Pop()

Dequeues the item at the front of the queue.

Declaration

cs-api-definition
public TValue Pop()

Returns

TValue

The item at the front of the queue.

Push(TValue)

Pushes the specified item in the queue.

Declaration

cs-api-definition
public void Push(TValue item)

Parameters

item

TValue

The item.

Push(TValue, TPriority)

Adds an item to the ICollection<T>.

Declaration

cs-api-definition
public void Push(TValue item, TPriority priority)

Parameters

item

TValue

The object to add to the ICollection<T>.

priority

TPriority

The priority of the item.

Remove(TValue)

Removes the specified item from this queue.

Declaration

cs-api-definition
public bool Remove(TValue item)

Parameters

item

TValue

The item.

Returns

bool

Implements ICollection<TValue>.Remove(TValue)

Remove(TValue, out TPriority)

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

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")]
public bool Remove(TValue item, out TPriority priority)

Parameters

item

TValue

The item to remove.

priority

TPriority

The priority associated with the item.

Returns

bool

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

RemovePriorityGroup(TPriority)

Removes the items with the specified priority.

Declaration

cs-api-definition
public bool RemovePriorityGroup(TPriority priority)

Parameters

priority

TPriority

The priority.

Returns

bool

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