ערוך

שתף באמצעות


PriorityQueue<TElement,TPriority> Class

Definition

Represents a collection of items that have a value and a priority. On dequeue, the item with the lowest priority value is removed.

generic <typename TElement, typename TPriority>
public ref class PriorityQueue
public class PriorityQueue<TElement,TPriority>
type PriorityQueue<'Element, 'Priority> = class
Public Class PriorityQueue(Of TElement, TPriority)

Type Parameters

TElement

Specifies the type of elements in the queue.

TPriority

Specifies the type of priority associated with enqueued elements.

Inheritance
PriorityQueue<TElement,TPriority>

Remarks

Implements an array-backed, quaternary min-heap. Each element is enqueued with an associated priority that determines the dequeue order. Elements with the lowest priority are dequeued first. Note that the type does not guarantee first-in-first-out semantics for elements of equal priority.

Constructors

PriorityQueue<TElement,TPriority>()

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

PriorityQueue<TElement,TPriority>(IComparer<TPriority>)

Initializes a new instance of the PriorityQueue<TElement,TPriority> class with the specified custom priority comparer.

PriorityQueue<TElement,TPriority>(IEnumerable<ValueTuple<TElement,TPriority>>)

Initializes a new instance of the PriorityQueue<TElement,TPriority> class that is populated with the specified elements and priorities.

PriorityQueue<TElement,TPriority>(IEnumerable<ValueTuple<TElement,TPriority>>, IComparer<TPriority>)

Initializes a new instance of the PriorityQueue<TElement,TPriority> class that is populated with the specified elements and priorities, and with the specified custom priority comparer.

PriorityQueue<TElement,TPriority>(Int32)

Initializes a new instance of the PriorityQueue<TElement,TPriority> class with the specified initial capacity.

PriorityQueue<TElement,TPriority>(Int32, IComparer<TPriority>)

Initializes a new instance of the PriorityQueue<TElement,TPriority> class with the specified initial capacity and custom priority comparer.

Properties

Comparer

Gets the priority comparer used by the PriorityQueue<TElement,TPriority>.

Count

Gets the number of elements contained in the PriorityQueue<TElement,TPriority>.

UnorderedItems

Gets a collection that enumerates the elements of the queue in an unordered manner.

Methods

Clear()

Removes all items from the PriorityQueue<TElement,TPriority>.

Dequeue()

Removes and returns the minimal element from the PriorityQueue<TElement,TPriority> - that is, the element with the lowest priority value.

DequeueEnqueue(TElement, TPriority)

Removes the minimal element and then immediately adds the specified element with associated priority to the PriorityQueue<TElement,TPriority>.

Enqueue(TElement, TPriority)

Adds the specified element with associated priority to the PriorityQueue<TElement,TPriority>.

EnqueueDequeue(TElement, TPriority)

Adds the specified element with associated priority to the PriorityQueue<TElement,TPriority>, and immediately removes the minimal element, returning the result.

EnqueueRange(IEnumerable<TElement>, TPriority)

Enqueues a sequence of elements pairs to the PriorityQueue<TElement,TPriority>, all associated with the specified priority.

EnqueueRange(IEnumerable<ValueTuple<TElement,TPriority>>)

Enqueues a sequence of element-priority pairs to the PriorityQueue<TElement,TPriority>.

EnsureCapacity(Int32)

Ensures that the PriorityQueue<TElement,TPriority> can hold up to capacity items without further expansion of its backing storage.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Peek()

Returns the minimal element from the PriorityQueue<TElement,TPriority> without removing it.

Remove(TElement, TElement, TPriority, IEqualityComparer<TElement>)

Removes the first occurrence that equals the specified parameter.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
TrimExcess()

Sets the capacity to the actual number of items in the PriorityQueue<TElement,TPriority>, if that is less than 90 percent of current capacity.

TryDequeue(TElement, TPriority)

Removes the minimal element from the PriorityQueue<TElement,TPriority>, and copies it and its associated priority to the element and priority arguments.

TryPeek(TElement, TPriority)

Returns a value that indicates whether there is a minimal element in the PriorityQueue<TElement,TPriority>, and if one is present, copies it and its associated priority to the element and priority arguments. The element is not removed from the PriorityQueue<TElement,TPriority>.

Applies to