Exemple #1
0
        public KeyValuePair <TPriority, TValue> Dequeue()
        {
            if (this.count == 0)
            {
                throw new InvalidOperationException();
            }

            var result = new KeyValuePair <TPriority, TValue>(
                this.next.Priority,
                this.next.Value);

            this.nodes.Remove(next);
            next.Next     = null;
            next.Parent   = null;
            next.Previous = null;
            next.Removed  = true;
            FibonacciHeapCell <TPriority, TValue> currentDegreeNode;

            if (degreeToNode.TryGetValue(next.Degree, out currentDegreeNode))
            {
                if (currentDegreeNode == next)
                {
                    degreeToNode.Remove(next.Degree);
                }
            }
            Contract.Assert(next.Children != null);
            foreach (var child in next.Children)
            {
                child.Parent = null;
            }
            nodes.MergeLists(next.Children);
            next.Children = null;
            count--;
            this.UpdateNext();

            return(result);
        }