// links y under x private void link(FibonacciHeapNode y, FibonacciHeapNode x) { removeFromSiblings(y); y.parent = x; if (x.child == null) x.child = y; else concatenateSiblings(x.child, y); x.degree++; y.mark = false; }
// cut node x from below y private void cut(FibonacciHeapNode x, FibonacciHeapNode y) { // remove x from y's children if (y.child == x) y.child = x.nextSibling; if (y.child == x) y.child = null; y.degree--; removeFromSiblings(x); concatenateSiblings(x, min); x.parent = null; x.mark = false; }
/** * Returns the object which has the <em>lowest</em> priority in the heap. If the heap is empty, * <code>null</code> is returned. */ public Object popMin() { if (min == null) return null; if (min.child != null) { FibonacciHeapNode tmp = min.child; // rempve parent pointers to min while (tmp.parent != null) { tmp.parent = null; tmp = tmp.nextSibling; } // add children of min to root list concatenateSiblings(tmp, min); } // remove min from root list FibonacciHeapNode oldMin = min; if (min.nextSibling == min) { min = null; } else { min = min.nextSibling; removeFromSiblings(oldMin); consolidate(); } itemsToNodes.remove(oldMin.userObject); return oldMin.userObject; }