Docs are now divided into modules.
2 #ifndef HUGO_BFS_ITERATOR_H
3 #define HUGO_BFS_ITERATOR_H
11 template <typename Graph, /*typename OutEdgeIt,*/
12 typename ReachedMap/*=typename Graph::NodeMap<bool>*/ >
15 typedef typename Graph::Node Node;
16 typedef typename Graph::OutEdgeIt OutEdgeIt;
18 std::queue<Node> bfs_queue;
20 bool b_node_newly_reached;
21 OutEdgeIt actual_edge;
24 BfsIterator(const Graph& _graph, ReachedMap& _reached) :
25 graph(&_graph), reached(_reached),
26 own_reached_map(false) { }
27 BfsIterator(const Graph& _graph) :
28 graph(&_graph), reached(*(new ReachedMap(*graph /*, false*/))),
29 own_reached_map(true) { }
30 ~BfsIterator() { if (own_reached_map) delete &reached; }
31 void pushAndSetReached(Node s) {
33 if (bfs_queue.empty()) {
35 graph->first(actual_edge, s);
36 if (graph->valid(actual_edge)) {
37 Node w=graph->bNode(actual_edge);
41 b_node_newly_reached=true;
43 b_node_newly_reached=false;
50 BfsIterator<Graph, /*OutEdgeIt,*/ ReachedMap>&
52 if (graph->valid(actual_edge)) {
53 graph->next(actual_edge);
54 if (graph->valid(actual_edge)) {
55 Node w=graph->bNode(actual_edge);
59 b_node_newly_reached=true;
61 b_node_newly_reached=false;
66 if (!bfs_queue.empty()) {
67 graph->first(actual_edge, bfs_queue.front());
68 if (graph->valid(actual_edge)) {
69 Node w=graph->bNode(actual_edge);
73 b_node_newly_reached=true;
75 b_node_newly_reached=false;
82 bool finished() const { return bfs_queue.empty(); }
83 operator OutEdgeIt () const { return actual_edge; }
84 bool isBNodeNewlyReached() const { return b_node_newly_reached; }
85 bool isANodeExamined() const { return !(graph->valid(actual_edge)); }
86 Node aNode() const { return bfs_queue.front(); }
87 Node bNode() const { return graph->bNode(actual_edge); }
88 const ReachedMap& getReachedMap() const { return reached; }
89 const std::queue<Node>& getBfsQueue() const { return bfs_queue; }
92 template <typename Graph, /*typename OutEdgeIt,*/
93 typename ReachedMap/*=typename Graph::NodeMap<bool>*/ >
96 typedef typename Graph::Node Node;
97 typedef typename Graph::OutEdgeIt OutEdgeIt;
99 std::stack<OutEdgeIt> dfs_stack;
100 bool b_node_newly_reached;
101 OutEdgeIt actual_edge;
104 bool own_reached_map;
106 DfsIterator(const Graph& _graph, ReachedMap& _reached) :
107 graph(&_graph), reached(_reached),
108 own_reached_map(false) { }
109 DfsIterator(const Graph& _graph) :
110 graph(&_graph), reached(*(new ReachedMap(*graph /*, false*/))),
111 own_reached_map(true) { }
112 ~DfsIterator() { if (own_reached_map) delete &reached; }
113 void pushAndSetReached(Node s) {
115 reached.set(s, true);
120 DfsIterator<Graph, /*OutEdgeIt,*/ ReachedMap>&
122 actual_edge=dfs_stack.top();
123 //actual_node=G.aNode(actual_edge);
124 if (graph->valid(actual_edge)/*.valid()*/) {
125 Node w=graph->bNode(actual_edge);
131 reached.set(w, true);
132 b_node_newly_reached=true;
134 actual_node=graph->aNode(actual_edge);
135 graph->next(dfs_stack.top());
136 b_node_newly_reached=false;
139 //actual_node=G.aNode(dfs_stack.top());
144 bool finished() const { return dfs_stack.empty(); }
145 operator OutEdgeIt () const { return actual_edge; }
146 bool isBNodeNewlyReached() const { return b_node_newly_reached; }
147 bool isANodeExamined() const { return !(graph->valid(actual_edge)); }
148 Node aNode() const { return actual_node; /*FIXME*/}
149 Node bNode() const { return graph->bNode(actual_edge); }
150 const ReachedMap& getReachedMap() const { return reached; }
151 const std::stack<OutEdgeIt>& getDfsStack() const { return dfs_stack; }
156 #endif //HUGO_BFS_ITERATOR_H