You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/07/12 03:04:26 UTC

svn commit: r1145415 - /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/collections/FibonacciHeap.java

Author: simonetripodi
Date: Tue Jul 12 01:04:26 2011
New Revision: 1145415

URL: http://svn.apache.org/viewvc?rev=1145415&view=rev
Log:
added inline comments in add() method - and fixed the minNode replacement bug!

Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/collections/FibonacciHeap.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/collections/FibonacciHeap.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/collections/FibonacciHeap.java?rev=1145415&r1=1145414&r2=1145415&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/collections/FibonacciHeap.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/collections/FibonacciHeap.java Tue Jul 12 01:04:26 2011
@@ -81,25 +81,38 @@ public final class FibonacciHeap<E>
             throw new NullPointerException();
         }
 
+        // FIB-HEAP-INSERT(H, x)
+
+        // p[x] <- NIL
+        // child[x] <- NIL
+        // left[x] <- x
+        // right[x] <- x
+        // mark[x] <- FALSE
         FibonacciHeapNode<E> node = new FibonacciHeapNode<E>( e );
 
+        // if min[H] = NIL
         if ( minimumNode == null )
         {
+            // then min[H] <- x
             minimumNode = node;
         }
         else
         {
+            // concatenate the root list containing x with root list H
             node.setLeft( minimumNode );
             node.setRight( minimumNode.getRight() );
             minimumNode.setRight( node );
             node.getRight().setLeft( minimumNode );
 
-            if ( compare( minimumNode.getValue(), e ) < 0 )
+            // if key[x] < key[min[H]]
+            if ( compare( e, minimumNode.getValue() ) < 0 )
             {
+                // then min[H] <- x
                 minimumNode = node;
             }
         }
 
+        // n[H] <- n[H] + 1
         size++;
         trees++;