Class IndexPriorityQueue<T>
- Namespace
- AlgorithmsSW.PriorityQueue
- Assembly
- AlgorithmsSW.dll
Represents a generic index-based priority queue where elements are ordered based on their priority determined by an IComparer.
public class IndexPriorityQueue<T>
Type Parameters
T
The type of elements in the priority queue.
- Inheritance
-
IndexPriorityQueue<T>
- Inherited Members
- Extension Methods
Remarks
This implementation of a priority queue uses an array-based binary heap. It associates each value with an index, allowing for efficient updates of the queue based on index.
Constructors
IndexPriorityQueue(int, IComparer<T>)
Initializes a new instance of the IndexPriorityQueue<T> class with a specified capacity and comparer.
public IndexPriorityQueue(int capacity, IComparer<T> comparer)
Parameters
capacity
intThe maximum number of elements the priority queue can hold.
comparer
IComparer<T>The IComparer to determine the priority of elements.
Properties
Count
Gets the number of elements currently in the priority queue.
public int Count { get; }
Property Value
IsEmpty
Gets a value indicating whether the priority queue is empty.
public bool IsEmpty { get; }
Property Value
Methods
Contains(int)
Determines whether the priority queue contains the specified index.
public bool Contains(int index)
Parameters
index
intThe index to check for presence in the queue.
Returns
Insert(int, T)
Inserts a value with an associated index into the priority queue.
public void Insert(int index, T value)
Parameters
index
intThe index associated with the value.
value
TThe value to insert.
PeekMin()
Returns the minimum element of the priority queue without removing it.
public (int index, T value) PeekMin()
Returns
PopMin()
Removes and returns the minimum element from the priority queue.
public (int index, T value) PopMin()
Returns
- (int index, T value)
A tuple containing the index and value of the minimum element that was removed.
UpdateValue(int, T)
Updates the value of the element at the specified index.
public void UpdateValue(int index, T newValue)
Parameters
index
intThe index of the element to update.
newValue
TThe new value to replace the current value.