src/work/bfs_iterator.hh
changeset 65 a63cef252656
parent 58 f71840c04b2a
child 75 87623302a68f
equal deleted inserted replaced
1:f8844b643298 2:2b39ed39bec8
   403     ReachedMap reached;
   403     ReachedMap reached;
   404     bool b_node_newly_reached;
   404     bool b_node_newly_reached;
   405     OutEdgeIt actual_edge;
   405     OutEdgeIt actual_edge;
   406   public:
   406   public:
   407     BfsIterator2(const Graph& _G) : G(_G), reached(G, false) { }
   407     BfsIterator2(const Graph& _G) : G(_G), reached(G, false) { }
   408     void pushAndSetReached(const NodeIt s) { 
   408     void pushAndSetReached(NodeIt s) { 
   409       reached.set(s, true);
   409       reached.set(s, true);
   410       if (bfs_queue.empty()) {
   410       if (bfs_queue.empty()) {
   411 	bfs_queue.push(G.template first<OutEdgeIt>(s));
   411 	bfs_queue.push(G.template first<OutEdgeIt>(s));
   412 	actual_edge=bfs_queue.front();
   412 	actual_edge=bfs_queue.front();
   413 	if (actual_edge.valid()) { 
   413 	if (actual_edge.valid()) { 
   442 	}
   442 	}
   443       } else {
   443       } else {
   444 	bfs_queue.pop(); 
   444 	bfs_queue.pop(); 
   445 	if (!bfs_queue.empty()) {
   445 	if (!bfs_queue.empty()) {
   446 	  actual_edge=bfs_queue.front();
   446 	  actual_edge=bfs_queue.front();
   447 	} else {
   447 	  if (actual_edge.valid()) {
   448 	  actual_edge=OutEdgeIt();
   448 	    NodeIt w=G.bNode(actual_edge);
   449 	}
   449 	    if (!reached.get(w)) {
   450 	if (actual_edge.valid()) {
   450 	      bfs_queue.push(G.template first<OutEdgeIt>(w));
   451 	  NodeIt w=G.bNode(actual_edge);
   451 	      reached.set(w, true);
   452 	  if (!reached.get(w)) {
   452 	      b_node_newly_reached=true;
   453 	    bfs_queue.push(G.template first<OutEdgeIt>(w));
   453 	    } else {
   454 	    reached.set(w, true);
   454 	      b_node_newly_reached=false;
   455 	    b_node_newly_reached=true;
   455 	    }
   456 	  } else {
       
   457 	    b_node_newly_reached=false;
       
   458 	  }
   456 	  }
   459 	}
   457 	}
   460       }
   458       }
   461       return *this;
   459       return *this;
   462     }
   460     }
   466     bool isANodeExamined() const { return !(actual_edge.valid()); }
   464     bool isANodeExamined() const { return !(actual_edge.valid()); }
   467     const ReachedMap& getReachedMap() const { return reached; }
   465     const ReachedMap& getReachedMap() const { return reached; }
   468     const std::queue<OutEdgeIt>& getBfsQueue() const { return bfs_queue; }
   466     const std::queue<OutEdgeIt>& getBfsQueue() const { return bfs_queue; }
   469  };
   467  };
   470 
   468 
   471 
       
   472 } // namespace marci
   469 } // namespace marci
   473 
   470 
   474 #endif //BFS_ITERATOR_HH
   471 #endif //BFS_ITERATOR_HH