base/common/src/main/com/thesett/common/util/FibonacciHeap.java
public E poll()
    {
        // Check if there is only one element in the heap.
        if (size == 1)
        {
            E result = minNode.element;

            // Set the minimum to null.
            minNode = null;

            // Decrease the count of elements in the heap.
            size--;

            return result;
        }

        // Check that there is a minimum element to return.
        else if (minNode != null)
        {
            // Get the minimum value that is to be returned.
            E result = minNode.element;

            // Promote the minimum nodes children into the root list but don't update their parent references. Updating
            // their parent references will be done later.
            if (minNode.degree > 0)
            {
                insertNodes(minNode, minNode.child);
            }

            // Cut the minimum node out of the root list and update the minimum to be old minimums next node. This
            // node may not really be the minimum but it is taken to be the initial candidate for a new minimum. The
            // real minimum will be scanned for later.
            minNode.next.prev = minNode.prev;
            minNode.prev.next = minNode.next;

            minNode = minNode.next;

            // The consolidation process will merge all the binomial trees of the same order until there are none
            // of duplicate size left. As each binomial tree of order k, Bk, holds 2^k nodes the biggest tree
            // possible for a heap of n nodes will be log to the base 2 of the next biggest power of 2 above or
            // equal to n. The next section of code creates an array with this many elements, indexed by the order
            // of the binomial tree, that is used to keep track of what tree orders currently exist during the
            // consolidation process.
            Node[] tree = (Node[]) Array.newInstance(minNode.getClass(), ceilingLog2(size - 1) + 1);

            // Loop through the root list, setting parent references to null and consolidating the remainder of the heap
            // into binomial trees. The loop begins at the next node after the min node and finishes on the min node
            // itself. This means that the min node is always the very last in the root list to be examined and
            // consolidated ensuring that it cannot have been removed from the root list before the loop gets to it. The
            // terminal min node is explicitly referenced because the consolidation process will update the min node
            // during the loop.
            Node nextNode = null;
            Node nextNextNode = minNode.next;
            Node terminalNode = minNode;

            do
            {
                // Move on to the next node.
                nextNode = nextNextNode;

                // Work out what the next next node will be at the start of the loop as manipulations durings
                // the loop may override the next node reference of the current next node.
                nextNextNode = nextNode.next;

                // Update parent references to null.
                nextNode.parent = null;

                // Update the minimum if the current root list element is smaller than the current best candidate.
                updateMinimum(nextNode);

                // Consolidate the remainder of the heap into binomial trees by merging duplicate trees of equal size.
                // Loop until no tree with the same size as the current one exists.
                int degree = nextNode.degree;
                Node parentNode = nextNode;

                while (tree[degree] != null)
                {
                    // Clear the binomial tree of this size from the tree array as it is about to be merged with the
                    // current node and a new tree of twice the size created.
                    Node mergeNode = tree[degree];

                    tree[degree] = null;

                    // Compare the roots of the two trees to be merged to decide which is the smaller and should form
                    // the single root of the merged tree.
                    if (compare(mergeNode, parentNode) < 0)
                    {
                        // Swap the two nodes.
                        Node temp = mergeNode;

                        mergeNode = parentNode;
                        parentNode = temp;
                    }

                    // Cut the tree rooted by the larger root node from the root list.
                    mergeNode.next.prev = mergeNode.prev;
                    mergeNode.prev.next = mergeNode.next;
                    mergeNode.next = mergeNode;
                    mergeNode.prev = mergeNode;

                    // Paste the tree rooted by the larger root node into the tree with the smaller root node.
                    mergeNode.parent = parentNode;

                    // Check if the smaller node (the parent) already has some children.
                    if (parentNode.child != null)
                    {
                        // Stitch the larger node into the circular doubly linked list of children.
                        insertNodes(parentNode.child, mergeNode);

                        // Update all the parent references of the newly added children.
                    }

                    // The smaller node does not already have children.
                    else
                    {
                        // Set the larger node (of degree 1) as its first child.
                        parentNode.child = mergeNode;

                        // Make sure the child node forms a doubly linked list with itself.
                        mergeNode.next = mergeNode;
                        mergeNode.prev = mergeNode;
                    }

                    // Bump up by one the order of the smaller root node to which the other tree of equal size was
                    // added.
                    parentNode.degree++;

                    // Continue the scan for duplicate trees on the next larger degree.
                    degree++;
                }

                tree[degree] = parentNode;
            }
            while (nextNode != terminalNode);

            /*
             * String out = "At End: ["; for (int i = 0; i < tree.length; i++) out += (i == tree.length - 1) ? tree[i] :
             * tree[i] + ", "; out += "]"; log.info(out);
             */

            // Decrease the count of elements in the heap.
            size--;

            // Return the minimum element.
            return result;
        }

        // There is no minimum element so return null.
        else
        {
            return null;
        }
    }
public E poll()
    {
        // Check if there is only one element in the heap.
        if (size == 1)
        {
            E result = minNode.element;

            // Set the minimum to null.
            minNode = null;

            // Decrease the count of elements in the heap.
            size--;

            return result;
        }

        // Check that there is a minimum element to return.
        else if (minNode != null)
        {
            // Get the minimum value that is to be returned.
            E result = minNode.element;

            // Promote the minimum nodes children into the root list but don't update their parent references. Updating
            // their parent references will be done later.
            if (minNode.degree > 0)
            {
                insertNodes(minNode, minNode.child);
            }

            // Cut the minimum node out of the root list and update the minimum to be old minimums next node. This
            // node may not really be the minimum but it is taken to be the initial candidate for a new minimum. The
            // real minimum will be scanned for later.
            minNode.next.prev = minNode.prev;
            minNode.prev.next = minNode.next;

            minNode = minNode.next;

            // The consolidation process will merge all the binomial trees of the same order until there are none
            // of duplicate size left. As each binomial tree of order k, Bk, holds 2^k nodes the biggest tree
            // possible for a heap of n nodes will be log to the base 2 of the next biggest power of 2 above or
            // equal to n. The next section of code creates an array with this many elements, indexed by the order
            // of the binomial tree, that is used to keep track of what tree orders currently exist during the
            // consolidation process.
            Node[] tree = (Node[]) Array.newInstance(minNode.getClass(), ceilingLog2(size - 1) + 1);

            // Loop through the root list, setting parent references to null and consolidating the remainder of the heap
            // into binomial trees. The loop begins at the next node after the min node and finishes on the min node
            // itself. This means that the min node is always the very last in the root list to be examined and
            // consolidated ensuring that it cannot have been removed from the root list before the loop gets to it. The
            // terminal min node is explicitly referenced because the consolidation process will update the min node
            // during the loop.
            Node nextNode = null;
            Node nextNextNode = minNode.next;
            Node terminalNode = minNode;

            do
            {
                // Move on to the next node.
                nextNode = nextNextNode;

                // Work out what the next next node will be at the start of the loop as manipulations durings
                // the loop may override the next node reference of the current next node.
                nextNextNode = nextNode.next;

                // Update parent references to null.
                nextNode.parent = null;

                // Update the minimum if the current root list element is smaller than the current best candidate.
                updateMinimum(nextNode);

                // Consolidate the remainder of the heap into binomial trees by merging duplicate trees of equal size.
                // Loop until no tree with the same size as the current one exists.
                int degree = nextNode.degree;
                Node parentNode = nextNode;

                while (tree[degree] != null)
                {
                    // Clear the binomial tree of this size from the tree array as it is about to be merged with the
                    // current node and a new tree of twice the size created.
                    Node mergeNode = tree[degree];

                    tree[degree] = null;

                    // Compare the roots of the two trees to be merged to decide which is the smaller and should form
                    // the single root of the merged tree.
                    if (compare(mergeNode, parentNode) < 0)
                    {
                        // Swap the two nodes.
                        Node temp = mergeNode;

                        mergeNode = parentNode;
                        parentNode = temp;
                    }

                    // Cut the tree rooted by the larger root node from the root list.
                    mergeNode.next.prev = mergeNode.prev;
                    mergeNode.prev.next = mergeNode.next;
                    mergeNode.next = mergeNode;
                    mergeNode.prev = mergeNode;

                    // Paste the tree rooted by the larger root node into the tree with the smaller root node.
                    mergeNode.parent = parentNode;

                    // Check if the smaller node (the parent) already has some children.
                    if (parentNode.child != null)
                    {
                        // Stitch the larger node into the circular doubly linked list of children.
                        insertNodes(parentNode.child, mergeNode);

                        // Update all the parent references of the newly added children.
                    }

                    // The smaller node does not already have children.
                    else
                    {
                        // Set the larger node (of degree 1) as its first child.
                        parentNode.child = mergeNode;

                        // Make sure the child node forms a doubly linked list with itself.
                        mergeNode.next = mergeNode;
                        mergeNode.prev = mergeNode;
                    }

                    // Bump up by one the order of the smaller root node to which the other tree of equal size was
                    // added.
                    parentNode.degree++;

                    // Continue the scan for duplicate trees on the next larger degree.
                    degree++;
                }

                tree[degree] = parentNode;
            }
            while (nextNode != terminalNode);

            /*
             * String out = "At End: ["; for (int i = 0; i < tree.length; i++) out += (i == tree.length - 1) ? tree[i] :
             * tree[i] + ", "; out += "]"; log.info(out);
             */

            // Decrease the count of elements in the heap.
            size--;

            // Return the minimum element.
            return result;
        }

        // There is no minimum element so return null.
        else
        {
            return null;
        }
    }
public E poll ( ) { // Check if there is only one element in the heap. if ( size == 1 ) { E result = minNode . element ; // Set the minimum to null. minNode = null ; // Decrease the count of elements in the heap. size -- ; return result ; } // Check that there is a minimum element to return. else if ( minNode != null ) { // Get the minimum value that is to be returned. E result = minNode . element ; // Promote the minimum nodes children into the root list but don't update their parent references. Updating // their parent references will be done later. if ( minNode . degree > 0 ) { insertNodes ( minNode , minNode . child ) ; } // Cut the minimum node out of the root list and update the minimum to be old minimums next node. This // node may not really be the minimum but it is taken to be the initial candidate for a new minimum. The // real minimum will be scanned for later. minNode . next . prev = minNode . prev ; minNode . prev . next = minNode . next ; minNode = minNode . next ; // The consolidation process will merge all the binomial trees of the same order until there are none // of duplicate size left. As each binomial tree of order k, Bk, holds 2^k nodes the biggest tree // possible for a heap of n nodes will be log to the base 2 of the next biggest power of 2 above or // equal to n. The next section of code creates an array with this many elements, indexed by the order // of the binomial tree, that is used to keep track of what tree orders currently exist during the // consolidation process. Node [ ] tree = ( Node [ ] ) Array . newInstance ( minNode . getClass ( ) , ceilingLog2 ( size - 1 ) + 1 ) ; // Loop through the root list, setting parent references to null and consolidating the remainder of the heap // into binomial trees. The loop begins at the next node after the min node and finishes on the min node // itself. This means that the min node is always the very last in the root list to be examined and // consolidated ensuring that it cannot have been removed from the root list before the loop gets to it. The // terminal min node is explicitly referenced because the consolidation process will update the min node // during the loop. Node nextNode = null ; Node nextNextNode = minNode . next ; Node terminalNode = minNode ; do { // Move on to the next node. nextNode = nextNextNode ; // Work out what the next next node will be at the start of the loop as manipulations durings // the loop may override the next node reference of the current next node. nextNextNode = nextNode . next ; // Update parent references to null. nextNode . parent = null ; // Update the minimum if the current root list element is smaller than the current best candidate. updateMinimum ( nextNode ) ; // Consolidate the remainder of the heap into binomial trees by merging duplicate trees of equal size. // Loop until no tree with the same size as the current one exists. int degree = nextNode . degree ; Node parentNode = nextNode ; while ( tree [ degree ] != null ) { // Clear the binomial tree of this size from the tree array as it is about to be merged with the // current node and a new tree of twice the size created. Node mergeNode = tree [ degree ] ; tree [ degree ] = null ; // Compare the roots of the two trees to be merged to decide which is the smaller and should form // the single root of the merged tree. if ( compare ( mergeNode , parentNode ) < 0 ) { // Swap the two nodes. Node temp = mergeNode ; mergeNode = parentNode ; parentNode = temp ; } // Cut the tree rooted by the larger root node from the root list. mergeNode . next . prev = mergeNode . prev ; mergeNode . prev . next = mergeNode . next ; mergeNode . next = mergeNode ; mergeNode . prev = mergeNode ; // Paste the tree rooted by the larger root node into the tree with the smaller root node. mergeNode . parent = parentNode ; // Check if the smaller node (the parent) already has some children. if ( parentNode . child != null ) { // Stitch the larger node into the circular doubly linked list of children. insertNodes ( parentNode . child , mergeNode ) ; // Update all the parent references of the newly added children. } // The smaller node does not already have children. else { // Set the larger node (of degree 1) as its first child. parentNode . child = mergeNode ; // Make sure the child node forms a doubly linked list with itself. mergeNode . next = mergeNode ; mergeNode . prev = mergeNode ; } // Bump up by one the order of the smaller root node to which the other tree of equal size was // added. parentNode . degree ++ ; // Continue the scan for duplicate trees on the next larger degree. degree ++ ; } tree [ degree ] = parentNode ; } while ( nextNode != terminalNode ) ; /*
             * String out = "At End: ["; for (int i = 0; i < tree.length; i++) out += (i == tree.length - 1) ? tree[i] :
             * tree[i] + ", "; out += "]"; log.info(out);
             */ // Decrease the count of elements in the heap. size -- ; // Return the minimum element. return result ; } // There is no minimum element so return null. else { return null ; } }
Retrieves and removes the (head) minimum element of this heap, or null if this heap is empty.

@return The head element of the hea, or null if the heap is empty.
Retrieves and removes the ( head ) minimum element of this heap or null if this heap is empty .