lemon/linear_heap.h
changeset 1905 b0b3fa857d72
parent 1875 98698b69a902
child 1906 7fa90b66ca9e
equal deleted inserted replaced
3:e0c4ee4bfa3e 4:769cf3c274be
   281       int idx = index[i];
   281       int idx = index[i];
   282       if (idx >= 0) idx = 0;
   282       if (idx >= 0) idx = 0;
   283       return state_enum(idx);
   283       return state_enum(idx);
   284     }
   284     }
   285 
   285 
       
   286     /// \brief Sets the state of the \c item in the heap.
       
   287     ///
       
   288     /// Sets the state of the \c item in the heap. It can be used to
       
   289     /// manually clear the heap when it is important to achive the
       
   290     /// better time complexity.
       
   291     /// \param i The item.
       
   292     /// \param st The state. It should not be \c IN_HEAP. 
       
   293     void state(const Item& i, state_enum st) {
       
   294       switch (st) {
       
   295       case POST_HEAP:
       
   296       case PRE_HEAP:
       
   297         if (state(i) == IN_HEAP) {
       
   298           erase(i);
       
   299         }
       
   300         index[i] = st;
       
   301         break;
       
   302       }
       
   303     }
       
   304 
   286   private:
   305   private:
   287 
   306 
   288     struct LinearItem {
   307     struct LinearItem {
   289       LinearItem(const Item& _item, int _value) 
   308       LinearItem(const Item& _item, int _value) 
   290 	: item(_item), value(_value) {}
   309 	: item(_item), value(_value) {}
   457       int idx = index[i];
   476       int idx = index[i];
   458       if (idx >= 0) idx = 0;
   477       if (idx >= 0) idx = 0;
   459       return state_enum(idx);
   478       return state_enum(idx);
   460     }
   479     }
   461 
   480 
       
   481     void state(const Item& i, state_enum st) {
       
   482       switch (st) {
       
   483       case POST_HEAP:
       
   484       case PRE_HEAP:
       
   485         if (state(i) == IN_HEAP) {
       
   486           erase(i);
       
   487         }
       
   488         index[i] = st;
       
   489         break;
       
   490       }
       
   491     }
       
   492 
   462   private:
   493   private:
   463 
   494 
   464     struct LinearItem {
   495     struct LinearItem {
   465       LinearItem(const Item& _item, int _value) 
   496       LinearItem(const Item& _item, int _value) 
   466 	: item(_item), value(_value) {}
   497 	: item(_item), value(_value) {}