Class UpdatablePriorityQueueExtensions
Extension methods for IUpdatablePriorityQueue<T> implementations.
Inheritance
Inherited Members
Namespace: MoreStructures.PriorityQueues.Extensions
Assembly: MoreStructures.dll
Syntax
public static class UpdatablePriorityQueueExtensions
Methods
| Improve this Doc View SourcePopAll<T>(IPriorityQueue<T>)
Pops in sequence all items of the provided queue
, returning the sequence of extracted items.
Declaration
public static IEnumerable<PrioritizedItem<T>> PopAll<T>(this IPriorityQueue<T> queue)
Parameters
Type | Name | Description |
---|---|---|
IPriorityQueue<T> | queue | The IPriorityQueue<T>, to extract all items of. |
Returns
Type | Description |
---|---|
IEnumerable<MoreStructures.PriorityQueues.PrioritizedItem<T>> | A sequence of extracted MoreStructures.PriorityQueues.PrioritizedItem<T>, in order of priority. |
Type Parameters
Name | Description |
---|---|
T | The type of items in the queue. |
PushOrUpdate<T>(IUpdatablePriorityQueue<T>, T, Int32)
If the provided item
already is in the queue
, it updates its priority to
the newPriority
. Otherwise, it pushes the item
in the
queue
, with the priority newPriority
.
Declaration
public static PrioritizedItem<T>? PushOrUpdate<T>(this IUpdatablePriorityQueue<T> queue, T item, int newPriority)
Parameters
Type | Name | Description |
---|---|---|
IUpdatablePriorityQueue<T> | queue | The IUpdatablePriorityQueue<T> instance to update. |
T | item | The item of type |
System.Int32 | newPriority | The new priority value. |
Returns
Type | Description |
---|---|
System.Nullable<MoreStructures.PriorityQueues.PrioritizedItem<T>> | The MoreStructures.PriorityQueues.PrioritizedItem<T> entry before the update, or null, if there was no entry
of |
Type Parameters
Name | Description |
---|---|
T | The type of items of the |
Remarks
ALGORITHM
- A Remove(T) of the provided item
is
attempted.
- Then, a Push(T, Int32) of the same item
is made, with
the newPriority
.
- Finally, the removed item, if any, is returned as result.
COMPLEXITY
- Time Complexity is O(Tremove + Tpush) and Space Complexity is O(Sremove + Spush), where Tremove and
Sremove are the time and space cost of Remove(T) and Tpush and
Spush are the time and space cost of Push(T, Int32), respectively.