[Lemon-commits] [lemon_svn] jacint: r228 - hugo/trunk/src/work/jacint

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:38:14 CET 2006


Author: jacint
Date: Tue Mar  9 19:42:14 2004
New Revision: 228

Modified:
   hugo/trunk/src/work/jacint/fib_heap.h

Log:
*** empty log message ***


Modified: hugo/trunk/src/work/jacint/fib_heap.h
==============================================================================
--- hugo/trunk/src/work/jacint/fib_heap.h	(original)
+++ hugo/trunk/src/work/jacint/fib_heap.h	Tue Mar  9 19:42:14 2004
@@ -15,8 +15,11 @@
  *
  *bool empty() : true iff size()=0
  *
- *void push(Item, Prio) : pushes Item to the heap with priority Prio. If
- *     Item was already in the heap, it calls decrease(Item, Prio) 
+ *void set(Item, Prio) : calls push(Item, Prio) if Item is not
+ *     in the heap, and calls decrease/increase(Item, Prio) otherwise
+ *
+ *void push(Item, Prio) : pushes Item to the heap with priority Prio. Item
+ *     mustn't be in the heap.
  *
  *Item top() : returns the Item with least Prio
  *
@@ -28,13 +31,10 @@
  *
  *void erase(Item) : deletes Item from the heap if it was already there
  *
- *void decrease(Item, P) : If Item was not in the heap, then it calls 
- *     push(Item, P). If item is in the heap with Prio more than P
- *     then sets its Prio to P.
- *
- *void increase(Item, P) : If Item was not in the heap, then it calls 
- *     push(Item, P). If item is in the heap with Prio less than P
- *     then sets its Prio to P.
+ *void decrease(Item, P) : decreases prio of Item to P. Item must be in the heap 
+ *     with prio at least P.
+ *
+ *void increase(Item, P) : sets prio of Item to P. 
  *
  *
  *In Fibonacci heaps, increase and erase are not efficient, in case of
@@ -80,42 +80,44 @@
     }
 
 
-   bool empty() const { return blank; }
-    
-    
-   void push (Item const it, PrioType const value) 
-   {
-   
-     int i=iimap.get(it);
-      
-     if ( i >= 0 && container[i].in ) decrease(it, value); 
-     else {
-       if ( i < 0 ) {
-	 int s=container.size();
-	 iimap.set( it, s );	
-	 store st;
-	 st.name=it;
-	 container.push_back(st);
-	 i=s;
-       }
-       
-       if ( !blank ) {
-	 container[container[minimum].right_neighbor].left_neighbor=i;
-	 container[i].right_neighbor=container[minimum].right_neighbor;
-	 container[minimum].right_neighbor=i;
-	 container[i].left_neighbor=minimum;
-	 if ( !comp( container[minimum].prio, value) ) minimum=i; 
+    bool empty() const { return blank; }
 
 
+    void set (Item const it, PrioType const value) {
+      int i=iimap.get(it);
+      if ( i >= 0 && container[i].in ) {
+	if ( !comp(container[i].prio, value) ) decrease(it, value); 
+	if ( comp(container[i].prio, value) ) increase(it, value); 
+      } else push(it, value);
+    }
+    
 
-       } else {
-	 container[i].right_neighbor=container[i].left_neighbor=i;
-	 minimum=i;	
-	 blank=false;
-       }
-       container[i].prio=value;
-     }
-   }
+    void push (Item const it, PrioType const value) {
+      int i=iimap.get(it);      
+      if ( i < 0 ) {
+	int s=container.size();
+	iimap.set( it, s );	
+	store st;
+	st.name=it;
+	container.push_back(st);
+	i=s;
+      }
+      
+      if ( !blank ) {
+	container[container[minimum].right_neighbor].left_neighbor=i;
+	container[i].right_neighbor=container[minimum].right_neighbor;
+	container[minimum].right_neighbor=i;
+	container[i].left_neighbor=minimum;
+	if ( !comp( container[minimum].prio, value) ) minimum=i; 
+	
+      } else {
+	container[i].right_neighbor=container[i].left_neighbor=i;
+	minimum=i;	
+	blank=false;
+      }
+      container[i].prio=value;
+    }
+    
 
 
     Item top() const {
@@ -199,36 +201,22 @@
    }
     
 
-   void decrease (Item it, PrioType const value) {
-     int i=iimap.get(it);
-     if ( i >= 0 && container[i].in ) { 
-       
-       if ( comp(value, container[i].prio) ) {
-	 container[i].prio=value;
-	 
-	 if ( container[i].parent!=-1 ) {
-	   int p=container[i].parent;
-	    
-	   if ( !comp(container[p].prio, value) ) { 
-	     cut(i,p);	    
-	     cascade(p);
-	     if ( comp(value, container[minimum].prio) ) minimum=i; 
-	   }
-	 } 
-       }
-     } else push(it, value);
-   }
+    void decrease (Item it, PrioType const value) {
+      int i=iimap.get(it);
+      container[i].prio=value;
+      int p=container[i].parent;
+ 
+      if ( p!=-1 && comp(value, container[p].prio) ) {
+	cut(i,p);	    
+	cascade(p);
+	if ( comp(value, container[minimum].prio) ) minimum=i; 
+      }
+    }
    
 
     void increase (Item it, PrioType const value) {
-      int i=iimap.get(it);
-      
-      if ( i >= 0 && container[i].in ) { 
-	if ( comp(container[i].prio, value) ) { 
-	  erase(it);
-	  push(it, value);
-	}
-      } else push(it, value);
+      erase(it);
+      push(it, value);
     }
 
 



More information about the Lemon-commits mailing list