src/work/jacint/bin_heap.hh
changeset 217 fc549fac0dd0
parent 170 9091b1ebca27
equal deleted inserted replaced
0:7e3d905d9c14 1:a726dcc475c9
   151     void pop() {
   151     void pop() {
   152       rmidx(0);
   152       rmidx(0);
   153     }
   153     }
   154 
   154 
   155     void erase(const Key &k) {
   155     void erase(const Key &k) {
   156       rmidx(kim.get(k));
   156       rmidx(kim[k]);
   157     }
   157     }
   158 
   158 
   159     const Val get(const Key &k) const {
   159     Val operator[](const Key &k) const {
   160       int idx = kim.get(k);
   160       int idx = kim[k];
   161       return data[idx].second;
   161       return data[idx].second;
   162     }
   162     }
       
   163     
   163     void put(const Key &k, const Val &v) {
   164     void put(const Key &k, const Val &v) {
   164       int idx = kim.get(k);
   165       int idx = kim[k];
   165       if( idx < 0 ) {
   166       if( idx < 0 ) {
   166 	push(k,v);
   167 	push(k,v);
   167       }
   168       }
   168       else if( comp(v, data[idx].second) ) {
   169       else if( comp(v, data[idx].second) ) {
   169 	bubble_up(idx, PairType(k,v));
   170 	bubble_up(idx, PairType(k,v));
   172 	bubble_down(idx, PairType(k,v), data.size());
   173 	bubble_down(idx, PairType(k,v), data.size());
   173       }
   174       }
   174     }
   175     }
   175 
   176 
   176     void decrease(const Key &k, const Val &v) {
   177     void decrease(const Key &k, const Val &v) {
   177       int idx = kim.get(k);
   178       int idx = kim[k];
   178       bubble_up(idx, PairType(k,v));
   179       bubble_up(idx, PairType(k,v));
   179     }
   180     }
   180     void increase(const Key &k, const Val &v) {
   181     void increase(const Key &k, const Val &v) {
   181       int idx = kim.get(k);
   182       int idx = kim[k];
   182       bubble_down(idx, PairType(k,v), data.size());
   183       bubble_down(idx, PairType(k,v), data.size());
   183     }
   184     }
   184 
   185 
   185     state_enum state(const Key &k) const {
   186     state_enum state(const Key &k) const {
   186       int s = kim.get(k);
   187       int s = kim[k];
   187       if( s>=0 )
   188       if( s>=0 )
   188 	s=0;
   189 	s=0;
   189       return state_enum(s);
   190       return state_enum(s);
   190     }
   191     }
   191 
   192