src/include/bin_heap.hh
changeset 41 67f73b15855d
parent 39 28b0d751d29f
child 114 bb07dd5b2d67
     1.1 --- a/src/include/bin_heap.hh	Tue Jan 27 21:36:17 2004 +0000
     1.2 +++ b/src/include/bin_heap.hh	Thu Jan 29 17:47:41 2004 +0000
     1.3 @@ -103,7 +103,7 @@
     1.4  
     1.5  
     1.6      int size() const { return data.size(); }
     1.7 -    bool empty() const { return size() == 0; }
     1.8 +    bool empty() const { return data.empty(); }
     1.9  
    1.10    private:
    1.11      static int parent(int i) { return (i-1)/2; }
    1.12 @@ -120,6 +120,17 @@
    1.13        kim.put(p.first, i);
    1.14      }
    1.15  
    1.16 +    void rmidx(int h) {
    1.17 +      int n = data.size()-1;
    1.18 +      if( h>=0 && h<=n ) {
    1.19 +	kim.put(data[h].first, POST_HEAP);
    1.20 +	if ( h<n ) {
    1.21 +	  bubble_down(h, data[n], n);
    1.22 +	}
    1.23 +	data.pop_back();
    1.24 +      }
    1.25 +    }
    1.26 +
    1.27    public:
    1.28      void push(const PairType &p) {
    1.29        int n = data.size();
    1.30 @@ -138,14 +149,11 @@
    1.31      }
    1.32  
    1.33      void pop() {
    1.34 -      int n = data.size()-1;
    1.35 -      if( n>=0 ) {
    1.36 -	kim.put(data[0].first, POST_HEAP);
    1.37 -	if ( n>0 ) {
    1.38 -	  bubble_down(0, data[n], n);
    1.39 -	}
    1.40 -	data.pop_back();
    1.41 -      }
    1.42 +      rmidx(0);
    1.43 +    }
    1.44 +
    1.45 +    void erase(const Key &k) {
    1.46 +      rmidx(kim.get(k));
    1.47      }
    1.48  
    1.49      const Val get(const Key &k) const {