diff -r c35afa9e89e7 -r ef88c0a30f85 lemon/elevator.h --- a/lemon/elevator.h Mon Jan 12 23:11:39 2009 +0100 +++ b/lemon/elevator.h Thu Nov 05 15:48:01 2009 +0100 @@ -27,6 +27,7 @@ ///for labeling items in push-relabel type algorithms. /// +#include #include namespace lemon { @@ -45,10 +46,10 @@ /// ///\sa LinkedElevator /// - ///\param Graph Type of the underlying graph. - ///\param Item Type of the items the data is assigned to (Graph::Node, - ///Graph::Arc, Graph::Edge). - template + ///\param GR Type of the underlying graph. + ///\param Item Type of the items the data is assigned to (\c GR::Node, + ///\c GR::Arc or \c GR::Edge). + template class Elevator { public: @@ -59,10 +60,10 @@ private: typedef Item *Vit; - typedef typename ItemSetTraits::template Map::Type VitMap; - typedef typename ItemSetTraits::template Map::Type IntMap; + typedef typename ItemSetTraits::template Map::Type VitMap; + typedef typename ItemSetTraits::template Map::Type IntMap; - const Graph &_g; + const GR &_g; int _max_level; int _item_num; VitMap _where; @@ -75,7 +76,7 @@ void copy(Item i, Vit p) { - _where.set(*p=i,p); + _where[*p=i] = p; } void copy(Vit s, Vit p) { @@ -83,15 +84,15 @@ { Item i=*s; *p=i; - _where.set(i,p); + _where[i] = p; } } void swap(Vit i, Vit j) { Item ti=*i; Vit ct = _where[ti]; - _where.set(ti,_where[*i=*j]); - _where.set(*j,ct); + _where[ti] = _where[*i=*j]; + _where[*j] = ct; *j=ti; } @@ -104,7 +105,7 @@ ///\param graph The underlying graph. ///\param max_level The maximum allowed level. ///Set the range of the possible labels to [0..max_level]. - Elevator(const Graph &graph,int max_level) : + Elevator(const GR &graph,int max_level) : _g(graph), _max_level(max_level), _item_num(_max_level), @@ -121,9 +122,9 @@ ///\param graph The underlying graph. ///Set the range of the possible labels to [0..max_level], ///where \c max_level is equal to the number of labeled items in the graph. - Elevator(const Graph &graph) : + Elevator(const GR &graph) : _g(graph), - _max_level(countItems(graph)), + _max_level(countItems(graph)), _item_num(_max_level), _where(graph), _level(graph,0), @@ -225,7 +226,7 @@ void liftHighestActive() { Item it = *_last_active[_highest_active]; - _level.set(it,_level[it]+1); + ++_level[it]; swap(_last_active[_highest_active]--,_last_active[_highest_active+1]); --_first[++_highest_active]; } @@ -248,7 +249,7 @@ --_last_active[l]; } copy(li,_first[new_level]); - _level.set(li,new_level); + _level[li] = new_level; _highest_active=new_level; } @@ -268,7 +269,7 @@ } copy(li,_first[_max_level]); --_last_active[_max_level]; - _level.set(li,_max_level); + _level[li] = _max_level; while(_highest_active>=0 && _last_active[_highest_active]<_first[_highest_active]) @@ -298,7 +299,7 @@ Item liftActiveOn(int level) { Item it =*_last_active[level]; - _level.set(it,_level[it]+1); + ++_level[it]; swap(_last_active[level]--, --_first[level+1]); if (level+1>_highest_active) ++_highest_active; } @@ -318,7 +319,7 @@ copy(--_first[l+1], _last_active[l]--); } copy(ai,_first[new_level]); - _level.set(ai,new_level); + _level[ai] = new_level; if (new_level>_highest_active) _highest_active=new_level; } @@ -338,7 +339,7 @@ } copy(ai,_first[_max_level]); --_last_active[_max_level]; - _level.set(ai,_max_level); + _level[ai] = _max_level; if (_highest_active==level) { while(_highest_active>=0 && @@ -369,7 +370,7 @@ copy(--_first[l+1],_last_active[l]--); } copy(i,_first[new_level]); - _level.set(i,new_level); + _level[i] = new_level; if(new_level>_highest_active) _highest_active=new_level; } @@ -381,7 +382,7 @@ ///only if you really know what it is for. ///\pre The item is on the top level. void dirtyTopButOne(Item i) { - _level.set(i,_max_level - 1); + _level[i] = _max_level - 1; } ///Lift all items on and above the given level to the top level. @@ -393,7 +394,7 @@ const Vit f=_first[l]; const Vit tl=_first[_max_level]; for(Vit i=f;i!=tl;++i) - _level.set(*i,_max_level); + _level[*i] = _max_level; for(int i=l;i<=_max_level;i++) { _first[i]=f; @@ -429,11 +430,11 @@ _first[0]=&_items[0]; _last_active[0]=&_items[0]-1; Vit n=&_items[0]; - for(typename ItemSetTraits::ItemIt i(_g);i!=INVALID;++i) + for(typename ItemSetTraits::ItemIt i(_g);i!=INVALID;++i) { *n=i; - _where.set(i,n); - _level.set(i,_max_level); + _where[i] = n; + _level[i] = _max_level; ++n; } } @@ -442,7 +443,7 @@ void initAddItem(Item i) { swap(_where[i],_init_num); - _level.set(i,_init_lev); + _level[i] = _init_lev; ++_init_num; } @@ -488,10 +489,10 @@ /// ///\sa Elevator /// - ///\param Graph Type of the underlying graph. - ///\param Item Type of the items the data is assigned to (Graph::Node, - ///Graph::Arc, Graph::Edge). - template + ///\param GR Type of the underlying graph. + ///\param Item Type of the items the data is assigned to (\c GR::Node, + ///\c GR::Arc or \c GR::Edge). + template class LinkedElevator { public: @@ -500,14 +501,14 @@ private: - typedef typename ItemSetTraits:: + typedef typename ItemSetTraits:: template Map::Type ItemMap; - typedef typename ItemSetTraits:: + typedef typename ItemSetTraits:: template Map::Type IntMap; - typedef typename ItemSetTraits:: + typedef typename ItemSetTraits:: template Map::Type BoolMap; - const Graph &_graph; + const GR &_graph; int _max_level; int _item_num; std::vector _first, _last; @@ -524,7 +525,7 @@ ///\param graph The underlying graph. ///\param max_level The maximum allowed level. ///Set the range of the possible labels to [0..max_level]. - LinkedElevator(const Graph& graph, int max_level) + LinkedElevator(const GR& graph, int max_level) : _graph(graph), _max_level(max_level), _item_num(_max_level), _first(_max_level + 1), _last(_max_level + 1), _prev(graph), _next(graph), @@ -537,8 +538,8 @@ ///\param graph The underlying graph. ///Set the range of the possible labels to [0..max_level], ///where \c max_level is equal to the number of labeled items in the graph. - LinkedElevator(const Graph& graph) - : _graph(graph), _max_level(countItems(graph)), + LinkedElevator(const GR& graph) + : _graph(graph), _max_level(countItems(graph)), _item_num(_max_level), _first(_max_level + 1), _last(_max_level + 1), _prev(graph, INVALID), _next(graph, INVALID), @@ -550,7 +551,7 @@ ///Activate item \c i. ///\pre Item \c i shouldn't be active before. void activate(Item i) { - _active.set(i, true); + _active[i] = true; int level = _level[i]; if (level > _highest_active) { @@ -559,16 +560,16 @@ if (_prev[i] == INVALID || _active[_prev[i]]) return; //unlace - _next.set(_prev[i], _next[i]); + _next[_prev[i]] = _next[i]; if (_next[i] != INVALID) { - _prev.set(_next[i], _prev[i]); + _prev[_next[i]] = _prev[i]; } else { _last[level] = _prev[i]; } //lace - _next.set(i, _first[level]); - _prev.set(_first[level], i); - _prev.set(i, INVALID); + _next[i] = _first[level]; + _prev[_first[level]] = i; + _prev[i] = INVALID; _first[level] = i; } @@ -578,23 +579,23 @@ ///Deactivate item \c i. ///\pre Item \c i must be active before. void deactivate(Item i) { - _active.set(i, false); + _active[i] = false; int level = _level[i]; if (_next[i] == INVALID || !_active[_next[i]]) goto find_highest_level; //unlace - _prev.set(_next[i], _prev[i]); + _prev[_next[i]] = _prev[i]; if (_prev[i] != INVALID) { - _next.set(_prev[i], _next[i]); + _next[_prev[i]] = _next[i]; } else { _first[_level[i]] = _next[i]; } //lace - _prev.set(i, _last[level]); - _next.set(_last[level], i); - _next.set(i, INVALID); + _prev[i] = _last[level]; + _next[_last[level]] = i; + _next[i] = INVALID; _last[level] = i; find_highest_level: @@ -684,21 +685,21 @@ void liftHighestActive() { Item i = _first[_highest_active]; if (_next[i] != INVALID) { - _prev.set(_next[i], INVALID); + _prev[_next[i]] = INVALID; _first[_highest_active] = _next[i]; } else { _first[_highest_active] = INVALID; _last[_highest_active] = INVALID; } - _level.set(i, ++_highest_active); + _level[i] = ++_highest_active; if (_first[_highest_active] == INVALID) { _first[_highest_active] = i; _last[_highest_active] = i; - _prev.set(i, INVALID); - _next.set(i, INVALID); + _prev[i] = INVALID; + _next[i] = INVALID; } else { - _prev.set(_first[_highest_active], i); - _next.set(i, _first[_highest_active]); + _prev[_first[_highest_active]] = i; + _next[i] = _first[_highest_active]; _first[_highest_active] = i; } } @@ -713,20 +714,20 @@ void liftHighestActive(int new_level) { Item i = _first[_highest_active]; if (_next[i] != INVALID) { - _prev.set(_next[i], INVALID); + _prev[_next[i]] = INVALID; _first[_highest_active] = _next[i]; } else { _first[_highest_active] = INVALID; _last[_highest_active] = INVALID; } - _level.set(i, _highest_active = new_level); + _level[i] = _highest_active = new_level; if (_first[_highest_active] == INVALID) { _first[_highest_active] = _last[_highest_active] = i; - _prev.set(i, INVALID); - _next.set(i, INVALID); + _prev[i] = INVALID; + _next[i] = INVALID; } else { - _prev.set(_first[_highest_active], i); - _next.set(i, _first[_highest_active]); + _prev[_first[_highest_active]] = i; + _next[i] = _first[_highest_active]; _first[_highest_active] = i; } } @@ -737,9 +738,9 @@ ///deactivate it. void liftHighestActiveToTop() { Item i = _first[_highest_active]; - _level.set(i, _max_level); + _level[i] = _max_level; if (_next[i] != INVALID) { - _prev.set(_next[i], INVALID); + _prev[_next[i]] = INVALID; _first[_highest_active] = _next[i]; } else { _first[_highest_active] = INVALID; @@ -773,20 +774,20 @@ { Item i = _first[l]; if (_next[i] != INVALID) { - _prev.set(_next[i], INVALID); + _prev[_next[i]] = INVALID; _first[l] = _next[i]; } else { _first[l] = INVALID; _last[l] = INVALID; } - _level.set(i, ++l); + _level[i] = ++l; if (_first[l] == INVALID) { _first[l] = _last[l] = i; - _prev.set(i, INVALID); - _next.set(i, INVALID); + _prev[i] = INVALID; + _next[i] = INVALID; } else { - _prev.set(_first[l], i); - _next.set(i, _first[l]); + _prev[_first[l]] = i; + _next[i] = _first[l]; _first[l] = i; } if (_highest_active < l) { @@ -802,20 +803,20 @@ { Item i = _first[l]; if (_next[i] != INVALID) { - _prev.set(_next[i], INVALID); + _prev[_next[i]] = INVALID; _first[l] = _next[i]; } else { _first[l] = INVALID; _last[l] = INVALID; } - _level.set(i, l = new_level); + _level[i] = l = new_level; if (_first[l] == INVALID) { _first[l] = _last[l] = i; - _prev.set(i, INVALID); - _next.set(i, INVALID); + _prev[i] = INVALID; + _next[i] = INVALID; } else { - _prev.set(_first[l], i); - _next.set(i, _first[l]); + _prev[_first[l]] = i; + _next[i] = _first[l]; _first[l] = i; } if (_highest_active < l) { @@ -831,13 +832,13 @@ { Item i = _first[l]; if (_next[i] != INVALID) { - _prev.set(_next[i], INVALID); + _prev[_next[i]] = INVALID; _first[l] = _next[i]; } else { _first[l] = INVALID; _last[l] = INVALID; } - _level.set(i, _max_level); + _level[i] = _max_level; if (l == _highest_active) { while (_highest_active >= 0 && activeFree(_highest_active)) --_highest_active; @@ -855,23 +856,23 @@ /// void lift(Item i, int new_level) { if (_next[i] != INVALID) { - _prev.set(_next[i], _prev[i]); + _prev[_next[i]] = _prev[i]; } else { _last[new_level] = _prev[i]; } if (_prev[i] != INVALID) { - _next.set(_prev[i], _next[i]); + _next[_prev[i]] = _next[i]; } else { _first[new_level] = _next[i]; } - _level.set(i, new_level); + _level[i] = new_level; if (_first[new_level] == INVALID) { _first[new_level] = _last[new_level] = i; - _prev.set(i, INVALID); - _next.set(i, INVALID); + _prev[i] = INVALID; + _next[i] = INVALID; } else { - _prev.set(_first[new_level], i); - _next.set(i, _first[new_level]); + _prev[_first[new_level]] = i; + _next[i] = _first[new_level]; _first[new_level] = i; } if (_highest_active < new_level) { @@ -887,7 +888,7 @@ ///only if you really know what it is for. ///\pre The item is on the top level. void dirtyTopButOne(Item i) { - _level.set(i, _max_level - 1); + _level[i] = _max_level - 1; } ///Lift all items on and above the given level to the top level. @@ -898,7 +899,7 @@ for (int i = l + 1; _first[i] != INVALID; ++i) { Item n = _first[i]; while (n != INVALID) { - _level.set(n, _max_level); + _level[n] = _max_level; n = _next[n]; } _first[i] = INVALID; @@ -934,25 +935,25 @@ _first[i] = _last[i] = INVALID; } _init_level = 0; - for(typename ItemSetTraits::ItemIt i(_graph); + for(typename ItemSetTraits::ItemIt i(_graph); i != INVALID; ++i) { - _level.set(i, _max_level); - _active.set(i, false); + _level[i] = _max_level; + _active[i] = false; } } ///Add an item to the current level. void initAddItem(Item i) { - _level.set(i, _init_level); + _level[i] = _init_level; if (_last[_init_level] == INVALID) { _first[_init_level] = i; _last[_init_level] = i; - _prev.set(i, INVALID); - _next.set(i, INVALID); + _prev[i] = INVALID; + _next[i] = INVALID; } else { - _prev.set(i, _last[_init_level]); - _next.set(i, INVALID); - _next.set(_last[_init_level], i); + _prev[i] = _last[_init_level]; + _next[i] = INVALID; + _next[_last[_init_level]] = i; _last[_init_level] = i; } }