[Lemon-commits] [lemon_svn] marci: r24 - hugo/trunk/src/work
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:36:53 CET 2006
Author: marci
Date: Mon Jan 12 12:48:49 2004
New Revision: 24
Modified:
hugo/trunk/src/work/marci_bfs.hh
Log:
bfs_iterator1
Modified: hugo/trunk/src/work/marci_bfs.hh
==============================================================================
--- hugo/trunk/src/work/marci_bfs.hh (original)
+++ hugo/trunk/src/work/marci_bfs.hh Mon Jan 12 12:48:49 2004
@@ -127,6 +127,56 @@
};
+ template <typename graph_type, typename reached_type>
+ struct bfs_iterator1 {
+ typedef typename graph_traits<graph_type>::node_iterator node_iterator;
+ typedef typename graph_traits<graph_type>::edge_iterator edge_iterator;
+ typedef typename graph_traits<graph_type>::each_node_iterator each_node_iterator;
+ typedef typename graph_traits<graph_type>::out_edge_iterator out_edge_iterator;
+
+ graph_type& G;
+ std::queue<out_edge_iterator>& bfs_queue;
+ reached_type& reached;
+ bool newly_reached;
+ bfs_iterator1(graph_type& _G, std::queue<out_edge_iterator>& _bfs_queue, reached_type& _reached) : G(_G), bfs_queue(_bfs_queue), reached(_reached) {
+ is_valid();
+ if (!bfs_queue.empty() && bfs_queue.front().is_valid()) {
+ out_edge_iterator e=bfs_queue.front();
+ node_iterator w=G.head(e);
+ if (!reached.get(w)) {
+ bfs_queue.push(G.first_out_edge(w));
+ reached.put(w, true);
+ newly_reached=true;
+ } else {
+ newly_reached=false;
+ }
+ }
+ }
+ bfs_iterator1<graph_type, reached_type>& operator++() {
+ if (!is_valid()) return *this;
+ ++(bfs_queue.front());
+ is_valid();
+ if (!bfs_queue.empty() && bfs_queue.front().is_valid()) {
+ out_edge_iterator e=bfs_queue.front();
+ node_iterator w=G.head(e);
+ if (!reached.get(w)) {
+ bfs_queue.push(G.first_out_edge(w));
+ reached.put(w, true);
+ newly_reached=true;
+ } else {
+ newly_reached=false;
+ }
+ }
+ return *this;
+ }
+ bool is_valid() {
+ while ( !bfs_queue.empty() && !bfs_queue.front().is_valid() ) { bfs_queue.pop(); }
+ if (bfs_queue.empty()) return false; else return true;
+ }
+ operator edge_iterator () { return bfs_queue.front(); }
+ bool is_newly_reached() { return newly_reached; }
+
+ };
} // namespace marci
More information about the Lemon-commits
mailing list