src/include/bin_heap.hh
changeset 218 5964f1c64ca1
parent 172 c645f4a2a6ae
child 221 d8a67c5b26d1
equal deleted inserted replaced
4:4966e0fb69f3 5:c3a7349bc1e1
   106     bool empty() const { return data.empty(); }
   106     bool empty() const { return data.empty(); }
   107 
   107 
   108   private:
   108   private:
   109     static int parent(int i) { return (i-1)/2; }
   109     static int parent(int i) { return (i-1)/2; }
   110     static int second_child(int i) { return 2*i+2; }
   110     static int second_child(int i) { return 2*i+2; }
   111     bool less(const PairType &p1, const PairType &p2) {
   111     bool less(const PairType &p1, const PairType &p2) const {
   112       return comp(p1.second, p2.second);
   112       return comp(p1.second, p2.second);
   113     }
   113     }
   114 
   114 
   115     int bubble_up(int hole, PairType p);
   115     int bubble_up(int hole, PairType p);
   116     int bubble_down(int hole, PairType p, int length);
   116     int bubble_down(int hole, PairType p, int length);
   154 
   154 
   155     void erase(const Item &i) {
   155     void erase(const Item &i) {
   156       rmidx(iim.get(i));
   156       rmidx(iim.get(i));
   157     }
   157     }
   158 
   158 
   159     const Prio get(const Item &i) const {
   159     Prio get(const Item &i) const {
   160       int idx = iim.get(i);
   160       int idx = iim.get(i);
   161       return data[idx].second;
   161       return data[idx].second;
       
   162     }
       
   163     Prio operator[](const Item &i) const {
       
   164       return get(i);
   162     }
   165     }
   163     void set(const Item &i, const Prio &p) {
   166     void set(const Item &i, const Prio &p) {
   164       int idx = iim.get(i);
   167       int idx = iim.get(i);
   165       if( idx < 0 ) {
   168       if( idx < 0 ) {
   166 	push(i,p);
   169 	push(i,p);