Click or drag to resize

PriorityQueueTAdjustFirstItem Method

Namespace:  Ookii.Jumbo
Assembly:  Ookii.Jumbo (in Ookii.Jumbo.dll) Version: 2.0.0
Syntax
public void AdjustFirstItem()
Exceptions
Remarks

If T is a reference type and not immutable, it may be possible to modify the value of items in the queue. In general, this is not allowed and doing this will break the priority queue and lead to undefined behaviour.

However, it is allowed to modify the current first element in the queue (which is returned by Peek) if this change is followed by an immediate call to AdjustFirstItem which re-evaluates the item's value and moves a different item to the front if necessary.

In the scenario that you are removing an item from the PriorityQueueT and immediately replacing it with a new one, using this function can yield better performance, as the sequence of Dequeue, modify, Enqueue(T) is twice as slow as doing Peek, modify, AdjustFirstItem.

Because the first element may change after calling AdjustFirstItem, it is not safe to continue modifying that same element afterwards. You must call Peek again to get the new front element which may now be changed.

This method is an O(log n) operation, where n is Count.

See Also