Development · Native API migration preview · Coverage validation in progress Published release →

API Browser

Class

PriorityArrayQueue<TElement, TPriority>

class PriorityArrayQueue<TElement, TPriority>

Module: System.Collections
Assembly: System.Runtime.dll
Source file: PriorityArrayQueue.rvn

Inheritance: Object → PriorityArrayQueue<TElement, TPriority>

An unsynchronized binary min-heap with an explicit priority comparer.

Remarks

Lowest priorities leave first. Equal priorities have no FIFO guarantee. Priorities and the comparer must retain stable ordering while queued. Comparer callbacks must not reenter queue operations (a terminal Fault). Storage grows geometrically; entries are stored inline without wrapper objects.

Development priority queue

PriorityArrayQueue<TElement, TPriority> is an unsynchronized binary min-heap. Pass a Comparer<TPriority> to the constructor; FunctionComparer<TPriority> adapts a callback. Comparison uses the sign of its result. Lowest priorities leave first; reversing the comparer produces a max-heap. Equal priorities have no FIFO promise. The comparer and queued priority values must retain a consistent ordering.

Peek and Dequeue return Optional<TElement>; PeekPriority returns Optional<TPriority>. Empty queues return None. Count, Capacity, and Comparer expose the current count, storage extent, and supplied policy. Clear removes all entries while retaining capacity. EnsureCapacity reserves slots without shrinking; negative capacities and comparer reentry into queue operations cause terminal Faults. Provider Faults are terminal, with no recovery/rollback guarantee. This is not a concurrent collection; simultaneous access requires external coordination.

Insertion and removal take O(log n) comparisons, peeking O(1), and clearing O(n). Storage uses parallel element and priority arrays, with geometric automatic growth. There are no per-entry heap-node wrappers. Growth copies the live entries into two new arrays, and removal clears vacated references. Returned Optional values and any allocations in the supplied comparer follow their normal runtime representation; this is not a blanket zero-allocation guarantee.

Compared with .NET's PriorityQueue, the min-priority and unspecified tie-order semantics match. neoCLR follows its existing explicit comparer and Optional-returning collection contracts, and names the array implementation. A binary heap keeps the initial implementation small; .NET uses a quaternary heap. No performance advantage over that implementation has been established. Sorted indexing, stable tie-breaking, bulk heapification, iteration, and arbitrary removal are not provided in this increment.

Constructors

2 items
PriorityArrayQueue(capacity: int, comparer: Comparer<TPriority>) Reserves capacity; a negative capacity causes a terminal Fault.
PriorityArrayQueue(comparer: Comparer<TPriority>) Creates an empty queue using the required ordering policy.

Properties

3 items
Capacity: int Number of entries that fit without growing storage.
Comparer: Comparer<TPriority> The ordering policy supplied at construction.
Count: int Number of queued elements.

Methods

10 items
Clear() -> () Removes all entries and releases their references, retaining capacity for reuse.
Dequeue() -> Optional<TElement> Removes the minimal element in O(log Count), or returns None when empty. Releases vacated storage references.
Enqueue(element: TElement, priority: TPriority) -> () Inserts an element in O(log Count) comparisons; growing storage takes O(Count).
EnsureCapacity(capacity: int) -> int Reserves at least capacity entries and returns the resulting capacity. Negative capacity faults.
Equals(other: object?) -> bool Tests reference identity by default; an ordinary class may override equality. Inherited from Object.Equals
GetHashCode() -> int Returns a stable identity hash by default; an ordinary class may override it consistently with equality. Inherited from Object.GetHashCode
GetType() -> TypeInfo Returns metadata for the concrete runtime type of this instance. Inherited from Object.GetType
Peek() -> Optional<TElement> Returns the minimal element without removing it, or None when empty.
PeekPriority() -> Optional<TPriority> Returns the minimal priority without removing it, or None when empty.
ToString() -> string Returns the concrete runtime type name for supported references, or display text from a class or boxed-struct override. Inherited from Object.ToString