public static FibonacciHeap <int, int> Create() { FibonacciHeap <int, int> fibonacciHeap = new FibonacciHeap <int, int>(); return(fibonacciHeap); }
public void Merge(FibonacciHeap <TPriority, TValue> other) { Contract.Requires(other != null); if (other.Direction != this.Direction) { throw new Exception("Error: Heaps must go in the same direction when merging"); } nodes.MergeLists(other.nodes); if ((priorityComparsion(other.Top.Priority, next.Priority) * DirectionMultiplier) < 0) { next = other.next; } count += other.Count; }
public IEnumerator <KeyValuePair <TPriority, TValue> > GetEnumerator() { var tempHeap = new FibonacciHeap <TPriority, TValue>(this.Direction, this.priorityComparsion); var nodeStack = new Stack <FibonacciHeapCell <TPriority, TValue> >(); LambdaHelpers.ForEach(nodes, x => nodeStack.Push(x)); while (nodeStack.Count > 0) { var topNode = nodeStack.Peek(); tempHeap.Enqueue(topNode.Priority, topNode.Value); nodeStack.Pop(); LambdaHelpers.ForEach(topNode.Children, x => nodeStack.Push(x)); } while (!tempHeap.IsEmpty) { yield return(tempHeap.Top.ToKeyValuePair()); tempHeap.Dequeue(); } }