Britbot
template<T >
void Britbot.PriorityQueue.HeapPriorityQueue< T >.Remove ( node) [inline]

Removes a node from the queue. Note that the node does not need to be the head of the queue. O(log n)

Implements Britbot.PriorityQueue.IPriorityQueue< T >.

Definition at line 264 of file HeapPriorityQueue.cs.

        {
            if (!this.Contains(node))
            {
                return;
            }

            if (this.Count <= 1)
            {
                this._nodes[1] = null;
                this.Count = 0;
                return;
            }

            //Make sure the node is the last node in the queue
            bool wasSwapped = false;
            T formerLastNode = this._nodes[this.Count];
            if (node.QueueIndex != this.Count)
            {
                //Swap the node with the last node
                this.Swap(node, formerLastNode);
                wasSwapped = true;
            }

            this.Count--;
            this._nodes[node.QueueIndex] = null;

            if (wasSwapped)
            {
                //Now bubble formerLastNode (which is no longer the last node) up or down as appropriate
                this.OnNodeUpdated(formerLastNode);
            }
        }