1.1 --- a/src/hugo/full_graph.h Wed Aug 25 18:55:57 2004 +0000
1.2 +++ b/src/hugo/full_graph.h Mon Aug 30 12:01:47 2004 +0000
1.3 @@ -63,12 +63,6 @@
1.4 Node tail(Edge e) const { return e.n%NodeNum; }
1.5 Node head(Edge e) const { return e.n/NodeNum; }
1.6
1.7 - Node aNode(OutEdgeIt e) const { return tail(e); }
1.8 - Node aNode(InEdgeIt e) const { return head(e); }
1.9 -
1.10 - Node bNode(OutEdgeIt e) const { return head(e); }
1.11 - Node bNode(InEdgeIt e) const { return tail(e); }
1.12 -
1.13 NodeIt& first(NodeIt& v) const {
1.14 v=NodeIt(*this); return v; }
1.15 EdgeIt& first(EdgeIt& e) const {
1.16 @@ -78,25 +72,23 @@
1.17 InEdgeIt& first(InEdgeIt& e, const Node v) const {
1.18 e=InEdgeIt(*this,v); return e; }
1.19
1.20 - static bool valid(Edge e) { return e.n!=-1; }
1.21 - static bool valid(Node n) { return n.n!=-1; }
1.22 -
1.23 - template <typename It> It getNext(It it) const
1.24 - { It tmp(it); return next(tmp); }
1.25 -
1.26 - NodeIt& next(NodeIt& it) const {
1.27 - it.n=(it.n+2)%(NodeNum+1)-1;
1.28 - return it;
1.29 - }
1.30 - OutEdgeIt& next(OutEdgeIt& it) const
1.31 - { it.n+=NodeNum; if(it.n>=EdgeNum) it.n=-1; return it; }
1.32 - InEdgeIt& next(InEdgeIt& it) const
1.33 - { if(!((++it.n)%NodeNum)) it.n=-1; return it; }
1.34 - static EdgeIt& next(EdgeIt& it) { --it.n; return it; }
1.35 -
1.36 static int id(Node v) { return v.n; }
1.37 static int id(Edge e) { return e.n; }
1.38
1.39 + /// Finds an edge between two nodes.
1.40 +
1.41 + /// Finds an edge from node \c u to node \c v.
1.42 + ///
1.43 + /// If \c prev is \ref INVALID (this is the default value), then
1.44 + /// It finds the first edge from \c u to \c v. Otherwise it looks for
1.45 + /// the next edge from \c u to \c v after \c prev.
1.46 + /// \return The found edge or INVALID if there is no such an edge.
1.47 + Edge findEdge(Node u,Node v, Edge prev = INVALID)
1.48 + {
1.49 + return prev.n==-1?Edge(*this,u.n,v.n):INVALID;
1.50 + }
1.51 +
1.52 +
1.53 class Node {
1.54 friend class FullGraph;
1.55 template <typename T> friend class NodeMap;
1.56 @@ -119,13 +111,15 @@
1.57 };
1.58
1.59 class NodeIt : public Node {
1.60 + const FullGraph *G;
1.61 friend class FullGraph;
1.62 public:
1.63 NodeIt() : Node() { }
1.64 + NodeIt(const FullGraph& _G,Node n) : Node(n), G(&_G) { }
1.65 NodeIt(Invalid i) : Node(i) { }
1.66 - NodeIt(const FullGraph& G) : Node(G.NodeNum?0:-1) { }
1.67 + NodeIt(const FullGraph& _G) : Node(_G.NodeNum?0:-1), G(&_G) { }
1.68 ///\todo Undocumented conversion Node -\> NodeIt.
1.69 - NodeIt(const FullGraph& G, const Node &n) : Node(n) { }
1.70 + NodeIt& operator++() { n=(n+2)%(G->NodeNum+1)-1;return *this; }
1.71 };
1.72
1.73 class Edge {
1.74 @@ -138,7 +132,8 @@
1.75 int n; //NodeNum*head+tail;
1.76 friend int FullGraph::id(Edge e);
1.77
1.78 - Edge(int nn) {n=nn;}
1.79 + Edge(int nn) : n(nn) {}
1.80 + Edge(const FullGraph &G, int tail, int head) : n(G.NodeNum*head+tail) {}
1.81 public:
1.82 Edge() { }
1.83 Edge (Invalid) { n=-1; }
1.84 @@ -154,30 +149,42 @@
1.85 class EdgeIt : public Edge {
1.86 friend class FullGraph;
1.87 public:
1.88 - EdgeIt(const FullGraph& G) : Edge(G.EdgeNum-1) { }
1.89 + EdgeIt(const FullGraph& _G) : Edge(_G.EdgeNum-1) { }
1.90 + EdgeIt(const FullGraph&, Edge e) : Edge(e) { }
1.91 EdgeIt (Invalid i) : Edge(i) { }
1.92 EdgeIt() : Edge() { }
1.93 + EdgeIt& operator++() { --n; return *this; }
1.94 +
1.95 ///\bug This is a workaround until somebody tells me how to
1.96 ///make class \c SymFullGraph::SymEdgeMap friend of Edge
1.97 int &idref() {return n;}
1.98 };
1.99
1.100 class OutEdgeIt : public Edge {
1.101 + const FullGraph *G;
1.102 friend class FullGraph;
1.103 public:
1.104 OutEdgeIt() : Edge() { }
1.105 + OutEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
1.106 OutEdgeIt (Invalid i) : Edge(i) { }
1.107
1.108 - OutEdgeIt(const FullGraph& G,const Node v)
1.109 - : Edge(v.n) {}
1.110 + OutEdgeIt(const FullGraph& _G,const Node v) : Edge(v.n), G(&_G) {}
1.111 +
1.112 + OutEdgeIt& operator++()
1.113 + { n+=G->NodeNum; if(n>=G->EdgeNum) n=-1; return *this; }
1.114 +
1.115 };
1.116
1.117 class InEdgeIt : public Edge {
1.118 + const FullGraph *G;
1.119 friend class FullGraph;
1.120 public:
1.121 InEdgeIt() : Edge() { }
1.122 + InEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
1.123 InEdgeIt (Invalid i) : Edge(i) { }
1.124 - InEdgeIt(const FullGraph& G,Node v) :Edge(v.n*G.NodeNum){}
1.125 + InEdgeIt(const FullGraph& _G,Node v) : Edge(v.n*_G.NodeNum), G(&_G) {}
1.126 + InEdgeIt& operator++()
1.127 + { if(!((++n)%G->NodeNum)) n=-1; return *this; }
1.128 };
1.129
1.130 template <typename T> class NodeMap
1.131 @@ -279,7 +286,7 @@
1.132 std::copy(m.container.begin(), m.container.end(), container.begin());
1.133 return *this;
1.134 }
1.135 -
1.136 +
1.137 void update() {}
1.138 void update(T a) {}
1.139 };