[Lemon-commits] [lemon_svn] klao: r56 - hugo/trunk/src/include

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


Author: klao
Date: Thu Jan 29 18:47:41 2004
New Revision: 56

Modified:
   hugo/trunk/src/include/bin_heap.hh

Log:
bin_heap.hh:
	erase metodus
	empty szebben :)


Modified: hugo/trunk/src/include/bin_heap.hh
==============================================================================
--- hugo/trunk/src/include/bin_heap.hh	(original)
+++ hugo/trunk/src/include/bin_heap.hh	Thu Jan 29 18:47:41 2004
@@ -103,7 +103,7 @@
 
 
     int size() const { return data.size(); }
-    bool empty() const { return size() == 0; }
+    bool empty() const { return data.empty(); }
 
   private:
     static int parent(int i) { return (i-1)/2; }
@@ -120,6 +120,17 @@
       kim.put(p.first, i);
     }
 
+    void rmidx(int h) {
+      int n = data.size()-1;
+      if( h>=0 && h<=n ) {
+	kim.put(data[h].first, POST_HEAP);
+	if ( h<n ) {
+	  bubble_down(h, data[n], n);
+	}
+	data.pop_back();
+      }
+    }
+
   public:
     void push(const PairType &p) {
       int n = data.size();
@@ -138,14 +149,11 @@
     }
 
     void pop() {
-      int n = data.size()-1;
-      if( n>=0 ) {
-	kim.put(data[0].first, POST_HEAP);
-	if ( n>0 ) {
-	  bubble_down(0, data[n], n);
-	}
-	data.pop_back();
-      }
+      rmidx(0);
+    }
+
+    void erase(const Key &k) {
+      rmidx(kim.get(k));
     }
 
     const Val get(const Key &k) const {



More information about the Lemon-commits mailing list