diff -r 2c52fc9781d4 -r 1b377a730d02 src/work/marci/bfs_iterator.h --- a/src/work/marci/bfs_iterator.h Mon Apr 05 15:31:21 2004 +0000 +++ b/src/work/marci/bfs_iterator.h Mon Apr 05 16:52:46 2004 +0000 @@ -5,7 +5,6 @@ #include #include #include -#include namespace hugo { @@ -630,40 +629,34 @@ // }; - template */ > + template */ > class BfsIterator5 { - typedef typename GraphWrapper::Node Node; - typedef typename GraphWrapper::OutEdgeIt OutEdgeIt; - GraphWrapper G; + protected: + typedef typename Graph::Node Node; + typedef typename Graph::OutEdgeIt OutEdgeIt; + const Graph* graph; std::queue bfs_queue; ReachedMap& reached; bool b_node_newly_reached; OutEdgeIt actual_edge; bool own_reached_map; public: - BfsIterator5(const GraphWrapper& _G, ReachedMap& _reached) : - G(_G), reached(_reached), + BfsIterator5(const Graph& _graph, ReachedMap& _reached) : + graph(&_graph), reached(_reached), own_reached_map(false) { } - BfsIterator5(const GraphWrapper& _G) : - G(_G), reached(*(new ReachedMap(G /*, false*/))), + BfsIterator5(const Graph& _graph) : + graph(&_graph), reached(*(new ReachedMap(*graph /*, false*/))), own_reached_map(true) { } -// BfsIterator5(const typename GraphWrapper::BaseGraph& _G, -// ReachedMap& _reached) : -// G(_G), reached(_reached), -// own_reached_map(false) { } -// BfsIterator5(const typename GraphWrapper::BaseGraph& _G) : -// G(_G), reached(*(new ReachedMap(G /*, false*/))), -// own_reached_map(true) { } ~BfsIterator5() { if (own_reached_map) delete &reached; } void pushAndSetReached(Node s) { reached.set(s, true); if (bfs_queue.empty()) { bfs_queue.push(s); - G./*getF*/first(actual_edge, s); - if (G.valid(actual_edge)/*.valid()*/) { - Node w=G.bNode(actual_edge); - if (!reached.get(w)) { + graph->first(actual_edge, s); + if (graph->valid(actual_edge)) { + Node w=graph->bNode(actual_edge); + if (!reached[w]) { bfs_queue.push(w); reached.set(w, true); b_node_newly_reached=true; @@ -675,13 +668,13 @@ bfs_queue.push(s); } } - BfsIterator5& + BfsIterator5& operator++() { - if (G.valid(actual_edge)/*.valid()*/) { - /*++*/G.next(actual_edge); - if (G.valid(actual_edge)/*.valid()*/) { - Node w=G.bNode(actual_edge); - if (!reached.get(w)) { + if (graph->valid(actual_edge)) { + graph->next(actual_edge); + if (graph->valid(actual_edge)) { + Node w=graph->bNode(actual_edge); + if (!reached[w]) { bfs_queue.push(w); reached.set(w, true); b_node_newly_reached=true; @@ -692,10 +685,10 @@ } else { bfs_queue.pop(); if (!bfs_queue.empty()) { - G./*getF*/first(actual_edge, bfs_queue.front()); - if (G.valid(actual_edge)/*.valid()*/) { - Node w=G.bNode(actual_edge); - if (!reached.get(w)) { + graph->first(actual_edge, bfs_queue.front()); + if (graph->valid(actual_edge)) { + Node w=graph->bNode(actual_edge); + if (!reached[w]) { bfs_queue.push(w); reached.set(w, true); b_node_newly_reached=true; @@ -710,9 +703,9 @@ bool finished() const { return bfs_queue.empty(); } operator OutEdgeIt () const { return actual_edge; } bool isBNodeNewlyReached() const { return b_node_newly_reached; } - bool isANodeExamined() const { return !(G.valid(actual_edge)/*.valid()*/); } + bool isANodeExamined() const { return !(graph->valid(actual_edge)); } Node aNode() const { return bfs_queue.front(); } - Node bNode() const { return G.bNode(actual_edge); } + Node bNode() const { return graph->bNode(actual_edge); } const ReachedMap& getReachedMap() const { return reached; } const std::queue& getBfsQueue() const { return bfs_queue; } }; @@ -773,12 +766,13 @@ // const std::stack& getDfsStack() const { return dfs_stack; } // }; - template */ > + template */ > class DfsIterator5 { - typedef typename GraphWrapper::Node Node; - typedef typename GraphWrapper::OutEdgeIt OutEdgeIt; - GraphWrapper G; + protected: + typedef typename Graph::Node Node; + typedef typename Graph::OutEdgeIt OutEdgeIt; + const Graph* graph; std::stack dfs_stack; bool b_node_newly_reached; OutEdgeIt actual_edge; @@ -786,36 +780,36 @@ ReachedMap& reached; bool own_reached_map; public: - DfsIterator5(const GraphWrapper& _G, ReachedMap& _reached) : - G(_G), reached(_reached), + DfsIterator5(const Graph& _graph, ReachedMap& _reached) : + graph(&_graph), reached(_reached), own_reached_map(false) { } - DfsIterator5(const GraphWrapper& _G) : - G(_G), reached(*(new ReachedMap(G /*, false*/))), + DfsIterator5(const Graph& _graph) : + graph(&_graph), reached(*(new ReachedMap(*graph /*, false*/))), own_reached_map(true) { } ~DfsIterator5() { if (own_reached_map) delete &reached; } void pushAndSetReached(Node s) { actual_node=s; reached.set(s, true); OutEdgeIt e; - G.first(e, s); + graph->first(e, s); dfs_stack.push(e); } - DfsIterator5& + DfsIterator5& operator++() { actual_edge=dfs_stack.top(); //actual_node=G.aNode(actual_edge); - if (G.valid(actual_edge)/*.valid()*/) { - Node w=G.bNode(actual_edge); + if (graph->valid(actual_edge)/*.valid()*/) { + Node w=graph->bNode(actual_edge); actual_node=w; - if (!reached.get(w)) { + if (!reached[w]) { OutEdgeIt e; - G.first(e, w); + graph->first(e, w); dfs_stack.push(e); reached.set(w, true); b_node_newly_reached=true; } else { - actual_node=G.aNode(actual_edge); - /*++*/G.next(dfs_stack.top()); + actual_node=graph->aNode(actual_edge); + graph->next(dfs_stack.top()); b_node_newly_reached=false; } } else { @@ -827,7 +821,7 @@ bool finished() const { return dfs_stack.empty(); } operator OutEdgeIt () const { return actual_edge; } bool isBNodeNewlyReached() const { return b_node_newly_reached; } - bool isANodeExamined() const { return !(G.valid(actual_edge)/*.valid()*/); } + bool isANodeExamined() const { return !(graph->valid(actual_edge)); } Node aNode() const { return actual_node; /*FIXME*/} Node bNode() const { return G.bNode(actual_edge); } const ReachedMap& getReachedMap() const { return reached; }