# HG changeset patch # User alpar # Date 1112261632 0 # Node ID f2255b96c19c4e4bdc6910e9ca8d12dbaa292a85 # Parent 7caed393608e4853e0402cdb994f6f9a4978545c It works again diff -r 7caed393608e -r f2255b96c19c src/work/alpar/boolmap_iter.cc --- a/src/work/alpar/boolmap_iter.cc Thu Mar 31 08:34:55 2005 +0000 +++ b/src/work/alpar/boolmap_iter.cc Thu Mar 31 09:33:52 2005 +0000 @@ -1,96 +1,103 @@ #include #include -#include +#include +#include using namespace lemon; ///\todo This is only a static map! -/// -template -class BoolIterEdgeMap +///\param BaseMap is an interger map. +template +class BoolIterMap { public: - typedef GG Graph; - typedef typename GG::Edge Edge; - typedef Edge Key; + typedef typename BaseMap::Key Key; typedef bool Value; friend class RefType; - friend class FalseIterator; - friend class TrueIterator; + friend class FalseIt; + friend class TrueIt; private: - Graph &G; - typename Graph::EdgeMap cref; - std::vector vals; + BaseMap &cref; + std::vector vals; int sep; //map[e] is true <=> cref[e]>=sep - bool isTrue(Edge e) {return cref[e]>=sep;} - void swap(Edge e, int s) + bool isTrue(Key k) {return cref[k]>=sep;} + void swap(Key k, int s) { - int ti=cref[e]; - Edge te=vals[s]; - cref[e]=s; vals[s]=e; - cref[te]=ti; vals[ti]=te; + int ti=cref[k]; + Key tk=vals[s]; + cref[k]=s; vals[s]=k; + cref[tk]=ti; vals[ti]=tk; } - void setTrue(Edge e) { if(cref[e]=sep) { swap(e,sep); sep++; } } + void setTrue(Key k) { if(cref[k]=sep) { swap(k,sep); sep++; } } public: - class FalseIterator + ///\e + void set(Key k,Value v) { if(v) setTrue(k); else setFalse(k);} + + ///\e + class FalseIt { - BoolIterEdgeMap &M; + const BoolIterMap &M; int i; public: - FalseIterator(BoolIterEdgeMap &_M) : M(_M), i(0) { } - FalseIterator &operator++() { ++i; return *this;} - operator Edge() { return i::max()) { } + FalseIt &operator++() { ++i; return *this;} + operator Key() { return i=M.sep; } }; - class TrueIterator + ///\e + class TrueIt { - BoolIterEdgeMap &M; + BoolIterMap &M; int i; public: - TrueIterator(BoolIterEdgeMap &_M) : M(_M), i(M.vals.size()-1) { } - TrueIterator &operator++() { --i; return *this;} - operator Edge() { return i>=M.sep ? M.vals[i] : INVALID; } - operator bool() { return i>=M.sep; } + explicit TrueIt(BoolIterMap &_M) : M(_M), i(M.vals.size()-1) { } + TrueIt(Invalid) + : M(*((BoolIterMap*)(0))), i(-1) { } + TrueIt &operator++() { --i; return *this;} + operator Key() { return i>=M.sep ? M.vals[i] : INVALID; } + bool operator !=(Invalid) { return i>=M.sep; } + bool operator ==(Invalid) { return isecond=sep; + vals.push_back(i->first); sep++; } } - RefType operator[] (Edge e) { return RefType(*this,e);} + RefType operator[] (Key k) { return RefType(*this,k);} + Value operator[] (Key k) const { return isTrue(k);} }; int main() @@ -104,28 +111,30 @@ for(int i=0;i<3;i++) G.addNode(); - for(NodeIt n(G);G.valid(n);G.next(n)) - for(NodeIt m(G);G.valid(m);G.next(m)) if(n!=m) + for(NodeIt n(G);n!=INVALID;++n) + for(NodeIt m(G);m!=INVALID;++m) if(n!=m) G.addEdge(n,m); //for(OutEdgeIt e(G,NodeIt(G));G.valid(e);G.next(e)) - BoolIterEdgeMap map(G); + Graph::EdgeMap tem(G); + typedef BoolIterMap > BoolIterEdgeMap; + BoolIterEdgeMap map(tem); bool b=true; - for(EdgeIt e(G);G.valid(e);G.next(e)) {map[e]=b;b=!b;} + for(EdgeIt e(G);e!=INVALID;++e) {map[e]=b;b=!b;} std::cout << true << '\n'; - for(EdgeIt e(G);G.valid(e);G.next(e)) + for(EdgeIt e(G);e!=INVALID;++e) std::cout << G.id(G.source(e)) << "->" << G.id(G.target(e)) << ": " << map[e] << '\n'; std::cout << "True Edges:\n"; - for(BoolIterEdgeMap::TrueIterator i(map);i;++i) + for(BoolIterEdgeMap::TrueIt i(map);i!=INVALID;++i) std::cout << G.id(G.source(i)) << "->" << G.id(G.target(i)) << '\n'; std::cout << "False Edges:\n"; - for(BoolIterEdgeMap::FalseIterator i(map);i;++i) + for(BoolIterEdgeMap::FalseIt i(map);i!=INVALID;++i) std::cout << G.id(G.source(i)) << "->" << G.id(G.target(i)) << '\n'; }