[Lemon-commits] [lemon_svn] alpar: r1040 - in hugo/branches/hugo++/src: hugo test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:42:54 CET 2006
Author: alpar
Date: Wed Aug 25 11:56:46 2004
New Revision: 1040
Modified:
hugo/branches/hugo++/src/hugo/full_graph.h
hugo/branches/hugo++/src/hugo/list_graph.h
hugo/branches/hugo++/src/hugo/smart_graph.h
hugo/branches/hugo++/src/test/graph_test.cc
Log:
'Edge findEdge(Node,Node,Edge);' function added.
Modified: hugo/branches/hugo++/src/hugo/full_graph.h
==============================================================================
--- hugo/branches/hugo++/src/hugo/full_graph.h (original)
+++ hugo/branches/hugo++/src/hugo/full_graph.h Wed Aug 25 11:56:46 2004
@@ -75,6 +75,20 @@
static int id(Node v) { return v.n; }
static int id(Edge e) { return e.n; }
+ /// Finds an edge between two nodes.
+
+ /// Finds an edge from node \c u to node \c v.
+ ///
+ /// If \c prev is \ref INVALID (this is the default value), then
+ /// It finds the first edge from \c u to \c v. Otherwise it looks for
+ /// the next edge from \c u to \c v after \c prev.
+ /// \return The found edge or INVALID if there is no such an edge.
+ Edge findEdge(Node u,Node v, Edge prev = INVALID)
+ {
+ return prev.n==-1?Edge(*this,u.n,v.n):INVALID;
+ }
+
+
class Node {
friend class FullGraph;
template <typename T> friend class NodeMap;
@@ -118,7 +132,8 @@
int n; //NodeNum*head+tail;
friend int FullGraph::id(Edge e);
- Edge(int nn) {n=nn;}
+ Edge(int nn) : n(nn) {}
+ Edge(const FullGraph &G, int tail, int head) : n(G.NodeNum*head+tail) {}
public:
Edge() { }
Edge (Invalid) { n=-1; }
@@ -268,7 +283,7 @@
std::copy(m.container.begin(), m.container.end(), container.begin());
return *this;
}
-
+
void update() {}
void update(T a) {}
};
Modified: hugo/branches/hugo++/src/hugo/list_graph.h
==============================================================================
--- hugo/branches/hugo++/src/hugo/list_graph.h (original)
+++ hugo/branches/hugo++/src/hugo/list_graph.h Wed Aug 25 11:56:46 2004
@@ -207,7 +207,23 @@
return e;
}
+
+ /// Finds an edge between two nodes.
+ /// Finds an edge from node \c u to node \c v.
+ ///
+ /// If \c prev is \ref INVALID (this is the default value), then
+ /// It finds the first edge from \c u to \c v. Otherwise it looks for
+ /// the next edge from \c u to \c v after \c prev.
+ /// \return The found edge or INVALID if there is no such an edge.
+ Edge findEdge(Node u,Node v, Edge prev = INVALID)
+ {
+ int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
+ while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
+ prev.n=e;
+ return prev;
+ }
+
private:
void eraseEdge(int n) {
@@ -889,6 +905,12 @@
i!=dyn_node_maps.end(); ++i) (**i).erase(nn);
}
+
+ Edge findEdge(Node u,Node v, Edge prev = INVALID)
+ {
+ return INVALID;
+ }
+
///\bug Dynamic maps must be updated!
///
void clear() {
@@ -1329,6 +1351,22 @@
return e;
}
+ /// Finds an edge between two nodes.
+
+ /// Finds an edge from node \c u to node \c v.
+ ///
+ /// If \c prev is \ref INVALID (this is the default value), then
+ /// It finds the first edge from \c u to \c v. Otherwise it looks for
+ /// the next edge from \c u to \c v after \c prev.
+ /// \return The found edge or INVALID if there is no such an edge.
+ Edge findEdge(Node u,Node v, Edge prev = INVALID)
+ {
+ int e = (prev.n==-1)? nodes[u].first_out : edges[prev.n].next_out;
+ while(e!=-1 && edges[e].tail!=v) e = edges[e].next_out;
+ prev.n=e;
+ return prev;
+ }
+
private:
void eraseEdge(int n) {
Modified: hugo/branches/hugo++/src/hugo/smart_graph.h
==============================================================================
--- hugo/branches/hugo++/src/hugo/smart_graph.h (original)
+++ hugo/branches/hugo++/src/hugo/smart_graph.h Wed Aug 25 11:56:46 2004
@@ -156,6 +156,22 @@
return e;
}
+ /// Finds an edge between two nodes.
+
+ /// Finds an edge from node \c u to node \c v.
+ ///
+ /// If \c prev is \ref INVALID (this is the default value), then
+ /// It finds the first edge from \c u to \c v. Otherwise it looks for
+ /// the next edge from \c u to \c v after \c prev.
+ /// \return The found edge or INVALID if there is no such an edge.
+ Edge findEdge(Node u,Node v, Edge prev = INVALID)
+ {
+ int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
+ while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
+ prev.n=e;
+ return prev;
+ }
+
void clear() {nodes.clear();edges.clear();}
class Node {
Modified: hugo/branches/hugo++/src/test/graph_test.cc
==============================================================================
--- hugo/branches/hugo++/src/test/graph_test.cc (original)
+++ hugo/branches/hugo++/src/test/graph_test.cc Wed Aug 25 11:56:46 2004
@@ -175,6 +175,9 @@
dm=cm; //Copy from another type
m=dm; //Copy to another type
}
+
+ //check findEdge
+ G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
}
More information about the Lemon-commits
mailing list