lemon/elevator.h
changeset 835 b9b2e8abe70b
parent 559 c5fd2d996909
equal deleted inserted replaced
7:25c16650089f 8:8347d666473c
    74 
    74 
    75     int _highest_active;
    75     int _highest_active;
    76 
    76 
    77     void copy(Item i, Vit p)
    77     void copy(Item i, Vit p)
    78     {
    78     {
    79       _where.set(*p=i,p);
    79       _where[*p=i] = p;
    80     }
    80     }
    81     void copy(Vit s, Vit p)
    81     void copy(Vit s, Vit p)
    82     {
    82     {
    83       if(s!=p)
    83       if(s!=p)
    84         {
    84         {
    85           Item i=*s;
    85           Item i=*s;
    86           *p=i;
    86           *p=i;
    87           _where.set(i,p);
    87           _where[i] = p;
    88         }
    88         }
    89     }
    89     }
    90     void swap(Vit i, Vit j)
    90     void swap(Vit i, Vit j)
    91     {
    91     {
    92       Item ti=*i;
    92       Item ti=*i;
    93       Vit ct = _where[ti];
    93       Vit ct = _where[ti];
    94       _where.set(ti,_where[*i=*j]);
    94       _where[ti] = _where[*i=*j];
    95       _where.set(*j,ct);
    95       _where[*j] = ct;
    96       *j=ti;
    96       *j=ti;
    97     }
    97     }
    98 
    98 
    99   public:
    99   public:
   100 
   100 
   224     ///Lift the item returned by highestActive() by one.
   224     ///Lift the item returned by highestActive() by one.
   225     ///
   225     ///
   226     void liftHighestActive()
   226     void liftHighestActive()
   227     {
   227     {
   228       Item it = *_last_active[_highest_active];
   228       Item it = *_last_active[_highest_active];
   229       _level.set(it,_level[it]+1);
   229       ++_level[it];
   230       swap(_last_active[_highest_active]--,_last_active[_highest_active+1]);
   230       swap(_last_active[_highest_active]--,_last_active[_highest_active+1]);
   231       --_first[++_highest_active];
   231       --_first[++_highest_active];
   232     }
   232     }
   233 
   233 
   234     ///Lift the highest active item to the given level.
   234     ///Lift the highest active item to the given level.
   247         {
   247         {
   248           copy(--_first[l+1],_first[l]);
   248           copy(--_first[l+1],_first[l]);
   249           --_last_active[l];
   249           --_last_active[l];
   250         }
   250         }
   251       copy(li,_first[new_level]);
   251       copy(li,_first[new_level]);
   252       _level.set(li,new_level);
   252       _level[li] = new_level;
   253       _highest_active=new_level;
   253       _highest_active=new_level;
   254     }
   254     }
   255 
   255 
   256     ///Lift the highest active item to the top level.
   256     ///Lift the highest active item to the top level.
   257 
   257 
   267           copy(--_first[l+1],_first[l]);
   267           copy(--_first[l+1],_first[l]);
   268           --_last_active[l];
   268           --_last_active[l];
   269         }
   269         }
   270       copy(li,_first[_max_level]);
   270       copy(li,_first[_max_level]);
   271       --_last_active[_max_level];
   271       --_last_active[_max_level];
   272       _level.set(li,_max_level);
   272       _level[li] = _max_level;
   273 
   273 
   274       while(_highest_active>=0 &&
   274       while(_highest_active>=0 &&
   275             _last_active[_highest_active]<_first[_highest_active])
   275             _last_active[_highest_active]<_first[_highest_active])
   276         _highest_active--;
   276         _highest_active--;
   277     }
   277     }
   297     ///Lift the active item returned by \ref activeOn() "activeOn(level)"
   297     ///Lift the active item returned by \ref activeOn() "activeOn(level)"
   298     ///by one.
   298     ///by one.
   299     Item liftActiveOn(int level)
   299     Item liftActiveOn(int level)
   300     {
   300     {
   301       Item it =*_last_active[level];
   301       Item it =*_last_active[level];
   302       _level.set(it,_level[it]+1);
   302       ++_level[it];
   303       swap(_last_active[level]--, --_first[level+1]);
   303       swap(_last_active[level]--, --_first[level+1]);
   304       if (level+1>_highest_active) ++_highest_active;
   304       if (level+1>_highest_active) ++_highest_active;
   305     }
   305     }
   306 
   306 
   307     ///Lift the active item returned by \c activeOn(level) to the given level.
   307     ///Lift the active item returned by \c activeOn(level) to the given level.
   317         {
   317         {
   318           copy(_last_active[l],_first[l]);
   318           copy(_last_active[l],_first[l]);
   319           copy(--_first[l+1], _last_active[l]--);
   319           copy(--_first[l+1], _last_active[l]--);
   320         }
   320         }
   321       copy(ai,_first[new_level]);
   321       copy(ai,_first[new_level]);
   322       _level.set(ai,new_level);
   322       _level[ai] = new_level;
   323       if (new_level>_highest_active) _highest_active=new_level;
   323       if (new_level>_highest_active) _highest_active=new_level;
   324     }
   324     }
   325 
   325 
   326     ///Lift the active item returned by \c activeOn(level) to the top level.
   326     ///Lift the active item returned by \c activeOn(level) to the top level.
   327 
   327 
   337           copy(_last_active[l],_first[l]);
   337           copy(_last_active[l],_first[l]);
   338           copy(--_first[l+1], _last_active[l]--);
   338           copy(--_first[l+1], _last_active[l]--);
   339         }
   339         }
   340       copy(ai,_first[_max_level]);
   340       copy(ai,_first[_max_level]);
   341       --_last_active[_max_level];
   341       --_last_active[_max_level];
   342       _level.set(ai,_max_level);
   342       _level[ai] = _max_level;
   343 
   343 
   344       if (_highest_active==level) {
   344       if (_highest_active==level) {
   345         while(_highest_active>=0 &&
   345         while(_highest_active>=0 &&
   346               _last_active[_highest_active]<_first[_highest_active])
   346               _last_active[_highest_active]<_first[_highest_active])
   347           _highest_active--;
   347           _highest_active--;
   368         {
   368         {
   369           copy(_last_active[l],_first[l]);
   369           copy(_last_active[l],_first[l]);
   370           copy(--_first[l+1],_last_active[l]--);
   370           copy(--_first[l+1],_last_active[l]--);
   371         }
   371         }
   372       copy(i,_first[new_level]);
   372       copy(i,_first[new_level]);
   373       _level.set(i,new_level);
   373       _level[i] = new_level;
   374       if(new_level>_highest_active) _highest_active=new_level;
   374       if(new_level>_highest_active) _highest_active=new_level;
   375     }
   375     }
   376 
   376 
   377     ///Move an inactive item to the top but one level (in a dirty way).
   377     ///Move an inactive item to the top but one level (in a dirty way).
   378 
   378 
   380     ///but one level (in a dirty way).
   380     ///but one level (in a dirty way).
   381     ///\warning It makes the underlying datastructure corrupt, so use it
   381     ///\warning It makes the underlying datastructure corrupt, so use it
   382     ///only if you really know what it is for.
   382     ///only if you really know what it is for.
   383     ///\pre The item is on the top level.
   383     ///\pre The item is on the top level.
   384     void dirtyTopButOne(Item i) {
   384     void dirtyTopButOne(Item i) {
   385       _level.set(i,_max_level - 1);
   385       _level[i] = _max_level - 1;
   386     }
   386     }
   387 
   387 
   388     ///Lift all items on and above the given level to the top level.
   388     ///Lift all items on and above the given level to the top level.
   389 
   389 
   390     ///This function lifts all items on and above level \c l to the top
   390     ///This function lifts all items on and above level \c l to the top
   392     void liftToTop(int l)
   392     void liftToTop(int l)
   393     {
   393     {
   394       const Vit f=_first[l];
   394       const Vit f=_first[l];
   395       const Vit tl=_first[_max_level];
   395       const Vit tl=_first[_max_level];
   396       for(Vit i=f;i!=tl;++i)
   396       for(Vit i=f;i!=tl;++i)
   397         _level.set(*i,_max_level);
   397         _level[*i] = _max_level;
   398       for(int i=l;i<=_max_level;i++)
   398       for(int i=l;i<=_max_level;i++)
   399         {
   399         {
   400           _first[i]=f;
   400           _first[i]=f;
   401           _last_active[i]=f-1;
   401           _last_active[i]=f-1;
   402         }
   402         }
   431       _last_active[0]=&_items[0]-1;
   431       _last_active[0]=&_items[0]-1;
   432       Vit n=&_items[0];
   432       Vit n=&_items[0];
   433       for(typename ItemSetTraits<GR,Item>::ItemIt i(_g);i!=INVALID;++i)
   433       for(typename ItemSetTraits<GR,Item>::ItemIt i(_g);i!=INVALID;++i)
   434         {
   434         {
   435           *n=i;
   435           *n=i;
   436           _where.set(i,n);
   436           _where[i] = n;
   437           _level.set(i,_max_level);
   437           _level[i] = _max_level;
   438           ++n;
   438           ++n;
   439         }
   439         }
   440     }
   440     }
   441 
   441 
   442     ///Add an item to the current level.
   442     ///Add an item to the current level.
   443     void initAddItem(Item i)
   443     void initAddItem(Item i)
   444     {
   444     {
   445       swap(_where[i],_init_num);
   445       swap(_where[i],_init_num);
   446       _level.set(i,_init_lev);
   446       _level[i] = _init_lev;
   447       ++_init_num;
   447       ++_init_num;
   448     }
   448     }
   449 
   449 
   450     ///Start a new level.
   450     ///Start a new level.
   451 
   451 
   549     ///Activate item \c i.
   549     ///Activate item \c i.
   550 
   550 
   551     ///Activate item \c i.
   551     ///Activate item \c i.
   552     ///\pre Item \c i shouldn't be active before.
   552     ///\pre Item \c i shouldn't be active before.
   553     void activate(Item i) {
   553     void activate(Item i) {
   554       _active.set(i, true);
   554       _active[i] = true;
   555 
   555 
   556       int level = _level[i];
   556       int level = _level[i];
   557       if (level > _highest_active) {
   557       if (level > _highest_active) {
   558         _highest_active = level;
   558         _highest_active = level;
   559       }
   559       }
   560 
   560 
   561       if (_prev[i] == INVALID || _active[_prev[i]]) return;
   561       if (_prev[i] == INVALID || _active[_prev[i]]) return;
   562       //unlace
   562       //unlace
   563       _next.set(_prev[i], _next[i]);
   563       _next[_prev[i]] = _next[i];
   564       if (_next[i] != INVALID) {
   564       if (_next[i] != INVALID) {
   565         _prev.set(_next[i], _prev[i]);
   565         _prev[_next[i]] = _prev[i];
   566       } else {
   566       } else {
   567         _last[level] = _prev[i];
   567         _last[level] = _prev[i];
   568       }
   568       }
   569       //lace
   569       //lace
   570       _next.set(i, _first[level]);
   570       _next[i] = _first[level];
   571       _prev.set(_first[level], i);
   571       _prev[_first[level]] = i;
   572       _prev.set(i, INVALID);
   572       _prev[i] = INVALID;
   573       _first[level] = i;
   573       _first[level] = i;
   574 
   574 
   575     }
   575     }
   576 
   576 
   577     ///Deactivate item \c i.
   577     ///Deactivate item \c i.
   578 
   578 
   579     ///Deactivate item \c i.
   579     ///Deactivate item \c i.
   580     ///\pre Item \c i must be active before.
   580     ///\pre Item \c i must be active before.
   581     void deactivate(Item i) {
   581     void deactivate(Item i) {
   582       _active.set(i, false);
   582       _active[i] = false;
   583       int level = _level[i];
   583       int level = _level[i];
   584 
   584 
   585       if (_next[i] == INVALID || !_active[_next[i]])
   585       if (_next[i] == INVALID || !_active[_next[i]])
   586         goto find_highest_level;
   586         goto find_highest_level;
   587 
   587 
   588       //unlace
   588       //unlace
   589       _prev.set(_next[i], _prev[i]);
   589       _prev[_next[i]] = _prev[i];
   590       if (_prev[i] != INVALID) {
   590       if (_prev[i] != INVALID) {
   591         _next.set(_prev[i], _next[i]);
   591         _next[_prev[i]] = _next[i];
   592       } else {
   592       } else {
   593         _first[_level[i]] = _next[i];
   593         _first[_level[i]] = _next[i];
   594       }
   594       }
   595       //lace
   595       //lace
   596       _prev.set(i, _last[level]);
   596       _prev[i] = _last[level];
   597       _next.set(_last[level], i);
   597       _next[_last[level]] = i;
   598       _next.set(i, INVALID);
   598       _next[i] = INVALID;
   599       _last[level] = i;
   599       _last[level] = i;
   600 
   600 
   601     find_highest_level:
   601     find_highest_level:
   602       if (level == _highest_active) {
   602       if (level == _highest_active) {
   603         while (_highest_active >= 0 && activeFree(_highest_active))
   603         while (_highest_active >= 0 && activeFree(_highest_active))
   683     ///Lift the item returned by highestActive() by one.
   683     ///Lift the item returned by highestActive() by one.
   684     ///
   684     ///
   685     void liftHighestActive() {
   685     void liftHighestActive() {
   686       Item i = _first[_highest_active];
   686       Item i = _first[_highest_active];
   687       if (_next[i] != INVALID) {
   687       if (_next[i] != INVALID) {
   688         _prev.set(_next[i], INVALID);
   688         _prev[_next[i]] = INVALID;
   689         _first[_highest_active] = _next[i];
   689         _first[_highest_active] = _next[i];
   690       } else {
   690       } else {
   691         _first[_highest_active] = INVALID;
   691         _first[_highest_active] = INVALID;
   692         _last[_highest_active] = INVALID;
   692         _last[_highest_active] = INVALID;
   693       }
   693       }
   694       _level.set(i, ++_highest_active);
   694       _level[i] = ++_highest_active;
   695       if (_first[_highest_active] == INVALID) {
   695       if (_first[_highest_active] == INVALID) {
   696         _first[_highest_active] = i;
   696         _first[_highest_active] = i;
   697         _last[_highest_active] = i;
   697         _last[_highest_active] = i;
   698         _prev.set(i, INVALID);
   698         _prev[i] = INVALID;
   699         _next.set(i, INVALID);
   699         _next[i] = INVALID;
   700       } else {
   700       } else {
   701         _prev.set(_first[_highest_active], i);
   701         _prev[_first[_highest_active]] = i;
   702         _next.set(i, _first[_highest_active]);
   702         _next[i] = _first[_highest_active];
   703         _first[_highest_active] = i;
   703         _first[_highest_active] = i;
   704       }
   704       }
   705     }
   705     }
   706 
   706 
   707     ///Lift the highest active item to the given level.
   707     ///Lift the highest active item to the given level.
   712     ///than the current level.
   712     ///than the current level.
   713     ///
   713     ///
   714     void liftHighestActive(int new_level) {
   714     void liftHighestActive(int new_level) {
   715       Item i = _first[_highest_active];
   715       Item i = _first[_highest_active];
   716       if (_next[i] != INVALID) {
   716       if (_next[i] != INVALID) {
   717         _prev.set(_next[i], INVALID);
   717         _prev[_next[i]] = INVALID;
   718         _first[_highest_active] = _next[i];
   718         _first[_highest_active] = _next[i];
   719       } else {
   719       } else {
   720         _first[_highest_active] = INVALID;
   720         _first[_highest_active] = INVALID;
   721         _last[_highest_active] = INVALID;
   721         _last[_highest_active] = INVALID;
   722       }
   722       }
   723       _level.set(i, _highest_active = new_level);
   723       _level[i] = _highest_active = new_level;
   724       if (_first[_highest_active] == INVALID) {
   724       if (_first[_highest_active] == INVALID) {
   725         _first[_highest_active] = _last[_highest_active] = i;
   725         _first[_highest_active] = _last[_highest_active] = i;
   726         _prev.set(i, INVALID);
   726         _prev[i] = INVALID;
   727         _next.set(i, INVALID);
   727         _next[i] = INVALID;
   728       } else {
   728       } else {
   729         _prev.set(_first[_highest_active], i);
   729         _prev[_first[_highest_active]] = i;
   730         _next.set(i, _first[_highest_active]);
   730         _next[i] = _first[_highest_active];
   731         _first[_highest_active] = i;
   731         _first[_highest_active] = i;
   732       }
   732       }
   733     }
   733     }
   734 
   734 
   735     ///Lift the highest active item to the top level.
   735     ///Lift the highest active item to the top level.
   736 
   736 
   737     ///Lift the item returned by highestActive() to the top level and
   737     ///Lift the item returned by highestActive() to the top level and
   738     ///deactivate it.
   738     ///deactivate it.
   739     void liftHighestActiveToTop() {
   739     void liftHighestActiveToTop() {
   740       Item i = _first[_highest_active];
   740       Item i = _first[_highest_active];
   741       _level.set(i, _max_level);
   741       _level[i] = _max_level;
   742       if (_next[i] != INVALID) {
   742       if (_next[i] != INVALID) {
   743         _prev.set(_next[i], INVALID);
   743         _prev[_next[i]] = INVALID;
   744         _first[_highest_active] = _next[i];
   744         _first[_highest_active] = _next[i];
   745       } else {
   745       } else {
   746         _first[_highest_active] = INVALID;
   746         _first[_highest_active] = INVALID;
   747         _last[_highest_active] = INVALID;
   747         _last[_highest_active] = INVALID;
   748       }
   748       }
   772     ///by one.
   772     ///by one.
   773     Item liftActiveOn(int l)
   773     Item liftActiveOn(int l)
   774     {
   774     {
   775       Item i = _first[l];
   775       Item i = _first[l];
   776       if (_next[i] != INVALID) {
   776       if (_next[i] != INVALID) {
   777         _prev.set(_next[i], INVALID);
   777         _prev[_next[i]] = INVALID;
   778         _first[l] = _next[i];
   778         _first[l] = _next[i];
   779       } else {
   779       } else {
   780         _first[l] = INVALID;
   780         _first[l] = INVALID;
   781         _last[l] = INVALID;
   781         _last[l] = INVALID;
   782       }
   782       }
   783       _level.set(i, ++l);
   783       _level[i] = ++l;
   784       if (_first[l] == INVALID) {
   784       if (_first[l] == INVALID) {
   785         _first[l] = _last[l] = i;
   785         _first[l] = _last[l] = i;
   786         _prev.set(i, INVALID);
   786         _prev[i] = INVALID;
   787         _next.set(i, INVALID);
   787         _next[i] = INVALID;
   788       } else {
   788       } else {
   789         _prev.set(_first[l], i);
   789         _prev[_first[l]] = i;
   790         _next.set(i, _first[l]);
   790         _next[i] = _first[l];
   791         _first[l] = i;
   791         _first[l] = i;
   792       }
   792       }
   793       if (_highest_active < l) {
   793       if (_highest_active < l) {
   794         _highest_active = l;
   794         _highest_active = l;
   795       }
   795       }
   801     ///to the given level.
   801     ///to the given level.
   802     void liftActiveOn(int l, int new_level)
   802     void liftActiveOn(int l, int new_level)
   803     {
   803     {
   804       Item i = _first[l];
   804       Item i = _first[l];
   805       if (_next[i] != INVALID) {
   805       if (_next[i] != INVALID) {
   806         _prev.set(_next[i], INVALID);
   806         _prev[_next[i]] = INVALID;
   807         _first[l] = _next[i];
   807         _first[l] = _next[i];
   808       } else {
   808       } else {
   809         _first[l] = INVALID;
   809         _first[l] = INVALID;
   810         _last[l] = INVALID;
   810         _last[l] = INVALID;
   811       }
   811       }
   812       _level.set(i, l = new_level);
   812       _level[i] = l = new_level;
   813       if (_first[l] == INVALID) {
   813       if (_first[l] == INVALID) {
   814         _first[l] = _last[l] = i;
   814         _first[l] = _last[l] = i;
   815         _prev.set(i, INVALID);
   815         _prev[i] = INVALID;
   816         _next.set(i, INVALID);
   816         _next[i] = INVALID;
   817       } else {
   817       } else {
   818         _prev.set(_first[l], i);
   818         _prev[_first[l]] = i;
   819         _next.set(i, _first[l]);
   819         _next[i] = _first[l];
   820         _first[l] = i;
   820         _first[l] = i;
   821       }
   821       }
   822       if (_highest_active < l) {
   822       if (_highest_active < l) {
   823         _highest_active = l;
   823         _highest_active = l;
   824       }
   824       }
   830     ///to the top level and deactivate it.
   830     ///to the top level and deactivate it.
   831     void liftActiveToTop(int l)
   831     void liftActiveToTop(int l)
   832     {
   832     {
   833       Item i = _first[l];
   833       Item i = _first[l];
   834       if (_next[i] != INVALID) {
   834       if (_next[i] != INVALID) {
   835         _prev.set(_next[i], INVALID);
   835         _prev[_next[i]] = INVALID;
   836         _first[l] = _next[i];
   836         _first[l] = _next[i];
   837       } else {
   837       } else {
   838         _first[l] = INVALID;
   838         _first[l] = INVALID;
   839         _last[l] = INVALID;
   839         _last[l] = INVALID;
   840       }
   840       }
   841       _level.set(i, _max_level);
   841       _level[i] = _max_level;
   842       if (l == _highest_active) {
   842       if (l == _highest_active) {
   843         while (_highest_active >= 0 && activeFree(_highest_active))
   843         while (_highest_active >= 0 && activeFree(_highest_active))
   844           --_highest_active;
   844           --_highest_active;
   845       }
   845       }
   846     }
   846     }
   854     /// \param new_level The new level of \c i. It must be strictly higher
   854     /// \param new_level The new level of \c i. It must be strictly higher
   855     /// than the current level.
   855     /// than the current level.
   856     ///
   856     ///
   857     void lift(Item i, int new_level) {
   857     void lift(Item i, int new_level) {
   858       if (_next[i] != INVALID) {
   858       if (_next[i] != INVALID) {
   859         _prev.set(_next[i], _prev[i]);
   859         _prev[_next[i]] = _prev[i];
   860       } else {
   860       } else {
   861         _last[new_level] = _prev[i];
   861         _last[new_level] = _prev[i];
   862       }
   862       }
   863       if (_prev[i] != INVALID) {
   863       if (_prev[i] != INVALID) {
   864         _next.set(_prev[i], _next[i]);
   864         _next[_prev[i]] = _next[i];
   865       } else {
   865       } else {
   866         _first[new_level] = _next[i];
   866         _first[new_level] = _next[i];
   867       }
   867       }
   868       _level.set(i, new_level);
   868       _level[i] = new_level;
   869       if (_first[new_level] == INVALID) {
   869       if (_first[new_level] == INVALID) {
   870         _first[new_level] = _last[new_level] = i;
   870         _first[new_level] = _last[new_level] = i;
   871         _prev.set(i, INVALID);
   871         _prev[i] = INVALID;
   872         _next.set(i, INVALID);
   872         _next[i] = INVALID;
   873       } else {
   873       } else {
   874         _prev.set(_first[new_level], i);
   874         _prev[_first[new_level]] = i;
   875         _next.set(i, _first[new_level]);
   875         _next[i] = _first[new_level];
   876         _first[new_level] = i;
   876         _first[new_level] = i;
   877       }
   877       }
   878       if (_highest_active < new_level) {
   878       if (_highest_active < new_level) {
   879         _highest_active = new_level;
   879         _highest_active = new_level;
   880       }
   880       }
   886     ///but one level (in a dirty way).
   886     ///but one level (in a dirty way).
   887     ///\warning It makes the underlying datastructure corrupt, so use it
   887     ///\warning It makes the underlying datastructure corrupt, so use it
   888     ///only if you really know what it is for.
   888     ///only if you really know what it is for.
   889     ///\pre The item is on the top level.
   889     ///\pre The item is on the top level.
   890     void dirtyTopButOne(Item i) {
   890     void dirtyTopButOne(Item i) {
   891       _level.set(i, _max_level - 1);
   891       _level[i] = _max_level - 1;
   892     }
   892     }
   893 
   893 
   894     ///Lift all items on and above the given level to the top level.
   894     ///Lift all items on and above the given level to the top level.
   895 
   895 
   896     ///This function lifts all items on and above level \c l to the top
   896     ///This function lifts all items on and above level \c l to the top
   897     ///level and deactivates them.
   897     ///level and deactivates them.
   898     void liftToTop(int l)  {
   898     void liftToTop(int l)  {
   899       for (int i = l + 1; _first[i] != INVALID; ++i) {
   899       for (int i = l + 1; _first[i] != INVALID; ++i) {
   900         Item n = _first[i];
   900         Item n = _first[i];
   901         while (n != INVALID) {
   901         while (n != INVALID) {
   902           _level.set(n, _max_level);
   902           _level[n] = _max_level;
   903           n = _next[n];
   903           n = _next[n];
   904         }
   904         }
   905         _first[i] = INVALID;
   905         _first[i] = INVALID;
   906         _last[i] = INVALID;
   906         _last[i] = INVALID;
   907       }
   907       }
   935         _first[i] = _last[i] = INVALID;
   935         _first[i] = _last[i] = INVALID;
   936       }
   936       }
   937       _init_level = 0;
   937       _init_level = 0;
   938       for(typename ItemSetTraits<GR,Item>::ItemIt i(_graph);
   938       for(typename ItemSetTraits<GR,Item>::ItemIt i(_graph);
   939           i != INVALID; ++i) {
   939           i != INVALID; ++i) {
   940         _level.set(i, _max_level);
   940         _level[i] = _max_level;
   941         _active.set(i, false);
   941         _active[i] = false;
   942       }
   942       }
   943     }
   943     }
   944 
   944 
   945     ///Add an item to the current level.
   945     ///Add an item to the current level.
   946     void initAddItem(Item i) {
   946     void initAddItem(Item i) {
   947       _level.set(i, _init_level);
   947       _level[i] = _init_level;
   948       if (_last[_init_level] == INVALID) {
   948       if (_last[_init_level] == INVALID) {
   949         _first[_init_level] = i;
   949         _first[_init_level] = i;
   950         _last[_init_level] = i;
   950         _last[_init_level] = i;
   951         _prev.set(i, INVALID);
   951         _prev[i] = INVALID;
   952         _next.set(i, INVALID);
   952         _next[i] = INVALID;
   953       } else {
   953       } else {
   954         _prev.set(i, _last[_init_level]);
   954         _prev[i] = _last[_init_level];
   955         _next.set(i, INVALID);
   955         _next[i] = INVALID;
   956         _next.set(_last[_init_level], i);
   956         _next[_last[_init_level]] = i;
   957         _last[_init_level] = i;
   957         _last[_init_level] = i;
   958       }
   958       }
   959     }
   959     }
   960 
   960 
   961     ///Start a new level.
   961     ///Start a new level.