[Lemon-commits] [lemon_svn] deba: r2064 - hugo/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:49:52 CET 2006
Author: deba
Date: Mon Jul 18 17:07:28 2005
New Revision: 2064
Modified:
hugo/trunk/lemon/graph_utils.h
Log:
Improve findEdge interface
ConEdgeIt is a high level replacement of findEdge
Modified: hugo/trunk/lemon/graph_utils.h
==============================================================================
--- hugo/trunk/lemon/graph_utils.h (original)
+++ hugo/trunk/lemon/graph_utils.h Mon Jul 18 17:07:28 2005
@@ -160,8 +160,35 @@
}
- /// Finds an edge between two nodes of a graph.
+ template <typename Graph>
+ inline
+ typename enable_if<typename Graph::FindEdgeTag, typename Graph::Edge>::type
+ _findEdge(const Graph &g,
+ typename Graph::Node u, typename Graph::Node v,
+ typename Graph::Edge prev = INVALID) {
+ return g.findEdge(u, v, prev);
+ }
+ template <typename Graph>
+ inline typename Graph::Edge
+ _findEdge(Wrap<Graph> w,
+ typename Graph::Node u,
+ typename Graph::Node v,
+ typename Graph::Edge prev = INVALID) {
+ const Graph& g = w.value;
+ if (prev == INVALID) {
+ typename Graph::OutEdgeIt e(g, u);
+ while (e != INVALID && g.target(e) != v) ++e;
+ return e;
+ } else {
+ typename Graph::OutEdgeIt e(g, prev); ++e;
+ while (e != INVALID && g.target(e) != v) ++e;
+ return e;
+ }
+ }
+
+ /// \brief Finds an edge between two nodes of a graph.
+ ///
/// Finds an edge from node \c u to node \c v in graph \c g.
///
/// If \c prev is \ref INVALID (this is the default value), then
@@ -175,22 +202,65 @@
/// ...
/// }
/// \endcode
- /// \todo We may want to use the "GraphBase"
- /// interface here...
- /// \bug Untested ...
+ // /// \todo We may want to use the "GraphBase"
+ // /// interface here...
+ // /// It would not work with the undirected graphs.
template <typename Graph>
- typename Graph::Edge findEdge(const Graph &g,
- typename Graph::Node u, typename Graph::Node v,
- typename Graph::Edge prev = INVALID)
- {
- typename Graph::OutEdgeIt e(g,prev);
- // if(prev==INVALID) g.first(e,u);
- if(prev==INVALID) e=typename Graph::OutEdgeIt(g,u);
- else ++e;
- while(e!=INVALID && g.target(e)!=v) ++e;
- return e;
+ inline typename Graph::Edge findEdge(const Graph &g,
+ typename Graph::Node u,
+ typename Graph::Node v,
+ typename Graph::Edge prev = INVALID) {
+ return _findEdge<Graph>(g, u, v, prev);
}
+ /// \brief Iterator for iterating on edges connected the same nodes.
+ ///
+ /// Iterator for iterating on edges connected the same nodes. It is
+ /// higher level interface for the findEdge() function. You can
+ /// use it the next way:
+ /// \code
+ /// for (ConEdgeIt<Graph> it(g, src, trg); it != INVALID; ++it) {
+ /// ...
+ /// }
+ /// \endcode
+ ///
+ /// \author Balazs Dezso
+ template <typename _Graph>
+ class ConEdgeIt : public _Graph::Edge {
+ public:
+
+ typedef _Graph Graph;
+ typedef typename Graph::Edge Parent;
+
+ typedef typename Graph::Edge Edge;
+ typedef typename Graph::Node Node;
+
+ /// \brief Constructor.
+ ///
+ /// Construct a new ConEdgeIt iterating on the edges which
+ /// connects the \c u and \c v node.
+ ConEdgeIt(const Graph& g, Node u, Node v) : graph(g) {
+ Parent::operator=(findEdge(graph, u, v));
+ }
+
+ /// \brief Constructor.
+ ///
+ /// Construct a new ConEdgeIt which continues the iterating from
+ /// the \c e edge.
+ ConEdgeIt(const Graph& g, Edge e) : Parent(e), graph(g) {}
+
+ /// \brief Increment operator.
+ ///
+ /// It increments the iterator and gives back the next edge.
+ ConEdgeIt& operator++() {
+ Parent::operator=(findEdge(graph, graph.source(*this),
+ graph.target(*this), *this));
+ return *this;
+ }
+ private:
+ const Graph& graph;
+ };
+
/// \brief Copy a map.
///
/// This function copies the \c source map to the \c target map. It uses the
More information about the Lemon-commits
mailing list