private void consolidate()

in src/main/java/org/apache/commons/graph/collections/FibonacciHeap.java [447:546]


    private void consolidate()
    {
        if ( isEmpty() )
        {
            return;
        }

        // D( n[H] ) <= log_phi( n[H] )
        // -> log_phi( n[H] ) = log( n[H] ) / log( phi )
        // -> D( n[H] ) = log( n[H] ) / log( phi )
        int arraySize = ( (int) floor( log( size ) / LOG_PHI ) );

        // 1  for i <- 0 to D(n[H])
        List<FibonacciHeapNode<E>> nodeSequence = new ArrayList<FibonacciHeapNode<E>>( arraySize );
        for ( int i = 0; i < arraySize; i++ )
        {
            // 2      do A[i] <- NIL
            nodeSequence.add( i, null );
        }

        int numRoots = 0;

        // 3  for each node x in the root list of H
        // 4  do x &larr; w
        FibonacciHeapNode<E> x = minimumNode;

        if ( x != null )
        {
            numRoots++;
            x = x.getRight();

            while ( x != minimumNode )
            {
                numRoots++;
                x = x.getRight();
            }
        }

        while ( numRoots > 0 )
        {
            // 5  d <- degree[x]
            int degree = x.getDegree();
            FibonacciHeapNode<E> next = x.getRight();

            // 6  while A[d] != NIL
            while ( nodeSequence.get( degree ) != null )
            {
                // 7  do y <- A[d]
                FibonacciHeapNode<E> y = nodeSequence.get( degree );

                // 8  if key[x] > key[y]
                if ( compare( x, y ) > 0 )
                {
                    // 9  exchange x <-> y
                    FibonacciHeapNode<E> pointer = y;
                    y = x;
                    x = pointer;
                }

                // 10  FIB-HEAP-LINK(H,y,x)
                link( y, x );

                // 11  A[d] <- NIL
                nodeSequence.set( degree, null );

                // 12  d <- d + 1
                degree++;
            }

            // 13  A[d] <- x
            nodeSequence.set( degree, x );

            x = next;
            numRoots--;
        }

        // 14  min[H] <- NIL
        minimumNode = null;

        // 15  for i <- 0 to D(n[H])
        for ( FibonacciHeapNode<E> pointer : nodeSequence )
        {
            if ( pointer == null )
            {
                continue;
            }
            if ( minimumNode == null )
            {
                minimumNode = pointer;
            }

            // 16 if A[i] != NIL
            // We've got a live one, add it to root list.
            if ( minimumNode != null )
            {
                //  First remove node from root list.
                moveToRoot( pointer );
            }
        }
    }