Granikos.SMTPSimulator.Service/PriorityQueue/HeapPriorityQueue.cs
/// <summary>
///     Removes a node from the queue.  Note that the node does not need to be the head of the queue.  O(log n)
/// </summary>
Removes a node from the queue.  Note that the node does not need to be the head of the queue.
Removes a node from the queue . Note that the node does not need to be the head of the queue .
public void Remove(T node)
        {
            if (!Contains(node))
            {
                return;
            }
            if (Count <= 1)
            {
                _nodes[1] = null;
                Count = 0;
                return;
            }
            var wasSwapped = false;
            var formerLastNode = _nodes[Count];
            if (node.QueueIndex != Count)
            {
                Swap(node, formerLastNode);
                wasSwapped = true;
            }
            Count--;
            _nodes[node.QueueIndex] = null;
            if (wasSwapped)
            {
                OnNodeUpdated(formerLastNode);
            }
        }
public void Remove ( T node ) { if ( ! Contains ( node ) ) { return ; } if ( Count <= 1 ) { _nodes [ 1 ] = null ; Count = 0 ; return ; } var wasSwapped = false ; var formerLastNode = _nodes [ Count ] ; if ( node . QueueIndex != Count ) { Swap ( node , formerLastNode ) ; wasSwapped = true ; } Count -- ; _nodes [ node . QueueIndex ] = null ; if ( wasSwapped ) { OnNodeUpdated ( formerLastNode ) ; } }
Removes a node from the queue.
Removes a node from the queue .
//Make sure the node is the last node in the queue //Swap the node with the last node //Now bubble formerLastNode (which is no longer the last node) up or down as appropriate
node
T