Changeset 758:28cfac049a6a in lemon for lemon/bin_heap.h
- Timestamp:
- 07/08/09 17:47:01 (16 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bin_heap.h
r757 r758 125 125 static int parent(int i) { return (i-1)/2; } 126 126 127 static int second _child(int i) { return 2*i+2; }127 static int secondChild(int i) { return 2*i+2; } 128 128 bool less(const Pair &p1, const Pair &p2) const { 129 129 return _comp(p1.second, p2.second); 130 130 } 131 131 132 int bubble _up(int hole, Pair p) {132 int bubbleUp(int hole, Pair p) { 133 133 int par = parent(hole); 134 134 while( hole>0 && less(p,_data[par]) ) { … … 141 141 } 142 142 143 int bubble _down(int hole, Pair p, int length) {144 int child = second _child(hole);143 int bubbleDown(int hole, Pair p, int length) { 144 int child = secondChild(hole); 145 145 while(child < length) { 146 146 if( less(_data[child-1], _data[child]) ) { … … 151 151 move(_data[child], hole); 152 152 hole = child; 153 child = second _child(hole);153 child = secondChild(hole); 154 154 } 155 155 child--; … … 179 179 int n = _data.size(); 180 180 _data.resize(n+1); 181 bubble _up(n, p);181 bubbleUp(n, p); 182 182 } 183 183 … … 215 215 _iim.set(_data[0].first, POST_HEAP); 216 216 if (n > 0) { 217 bubble _down(0, _data[n], n);217 bubbleDown(0, _data[n], n); 218 218 } 219 219 _data.pop_back(); … … 231 231 _iim.set(_data[h].first, POST_HEAP); 232 232 if( h < n ) { 233 if ( bubble _up(h, _data[n]) == h) {234 bubble _down(h, _data[n], n);233 if ( bubbleUp(h, _data[n]) == h) { 234 bubbleDown(h, _data[n], n); 235 235 } 236 236 } … … 262 262 } 263 263 else if( _comp(p, _data[idx].second) ) { 264 bubble _up(idx, Pair(i,p));264 bubbleUp(idx, Pair(i,p)); 265 265 } 266 266 else { 267 bubble _down(idx, Pair(i,p), _data.size());267 bubbleDown(idx, Pair(i,p), _data.size()); 268 268 } 269 269 } … … 277 277 void decrease(const Item &i, const Prio &p) { 278 278 int idx = _iim[i]; 279 bubble _up(idx, Pair(i,p));279 bubbleUp(idx, Pair(i,p)); 280 280 } 281 281 … … 288 288 void increase(const Item &i, const Prio &p) { 289 289 int idx = _iim[i]; 290 bubble _down(idx, Pair(i,p), _data.size());290 bubbleDown(idx, Pair(i,p), _data.size()); 291 291 } 292 292
Note: See TracChangeset
for help on using the changeset viewer.