diff -r ce9438c5a82d -r 4297098d9677 src/hugo/full_graph.h --- a/src/hugo/full_graph.h Wed Aug 25 18:55:57 2004 +0000 +++ b/src/hugo/full_graph.h Mon Aug 30 12:01:47 2004 +0000 @@ -63,12 +63,6 @@ Node tail(Edge e) const { return e.n%NodeNum; } Node head(Edge e) const { return e.n/NodeNum; } - Node aNode(OutEdgeIt e) const { return tail(e); } - Node aNode(InEdgeIt e) const { return head(e); } - - Node bNode(OutEdgeIt e) const { return head(e); } - Node bNode(InEdgeIt e) const { return tail(e); } - NodeIt& first(NodeIt& v) const { v=NodeIt(*this); return v; } EdgeIt& first(EdgeIt& e) const { @@ -78,25 +72,23 @@ InEdgeIt& first(InEdgeIt& e, const Node v) const { e=InEdgeIt(*this,v); return e; } - static bool valid(Edge e) { return e.n!=-1; } - static bool valid(Node n) { return n.n!=-1; } - - template It getNext(It it) const - { It tmp(it); return next(tmp); } - - NodeIt& next(NodeIt& it) const { - it.n=(it.n+2)%(NodeNum+1)-1; - return it; - } - OutEdgeIt& next(OutEdgeIt& it) const - { it.n+=NodeNum; if(it.n>=EdgeNum) it.n=-1; return it; } - InEdgeIt& next(InEdgeIt& it) const - { if(!((++it.n)%NodeNum)) it.n=-1; return it; } - static EdgeIt& next(EdgeIt& it) { --it.n; return it; } - 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 friend class NodeMap; @@ -119,13 +111,15 @@ }; class NodeIt : public Node { + const FullGraph *G; friend class FullGraph; public: NodeIt() : Node() { } + NodeIt(const FullGraph& _G,Node n) : Node(n), G(&_G) { } NodeIt(Invalid i) : Node(i) { } - NodeIt(const FullGraph& G) : Node(G.NodeNum?0:-1) { } + NodeIt(const FullGraph& _G) : Node(_G.NodeNum?0:-1), G(&_G) { } ///\todo Undocumented conversion Node -\> NodeIt. - NodeIt(const FullGraph& G, const Node &n) : Node(n) { } + NodeIt& operator++() { n=(n+2)%(G->NodeNum+1)-1;return *this; } }; class Edge { @@ -138,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; } @@ -154,30 +149,42 @@ class EdgeIt : public Edge { friend class FullGraph; public: - EdgeIt(const FullGraph& G) : Edge(G.EdgeNum-1) { } + EdgeIt(const FullGraph& _G) : Edge(_G.EdgeNum-1) { } + EdgeIt(const FullGraph&, Edge e) : Edge(e) { } EdgeIt (Invalid i) : Edge(i) { } EdgeIt() : Edge() { } + EdgeIt& operator++() { --n; return *this; } + ///\bug This is a workaround until somebody tells me how to ///make class \c SymFullGraph::SymEdgeMap friend of Edge int &idref() {return n;} }; class OutEdgeIt : public Edge { + const FullGraph *G; friend class FullGraph; public: OutEdgeIt() : Edge() { } + OutEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { } OutEdgeIt (Invalid i) : Edge(i) { } - OutEdgeIt(const FullGraph& G,const Node v) - : Edge(v.n) {} + OutEdgeIt(const FullGraph& _G,const Node v) : Edge(v.n), G(&_G) {} + + OutEdgeIt& operator++() + { n+=G->NodeNum; if(n>=G->EdgeNum) n=-1; return *this; } + }; class InEdgeIt : public Edge { + const FullGraph *G; friend class FullGraph; public: InEdgeIt() : Edge() { } + InEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { } InEdgeIt (Invalid i) : Edge(i) { } - InEdgeIt(const FullGraph& G,Node v) :Edge(v.n*G.NodeNum){} + InEdgeIt(const FullGraph& _G,Node v) : Edge(v.n*_G.NodeNum), G(&_G) {} + InEdgeIt& operator++() + { if(!((++n)%G->NodeNum)) n=-1; return *this; } }; template class NodeMap @@ -279,7 +286,7 @@ std::copy(m.container.begin(), m.container.end(), container.begin()); return *this; } - + void update() {} void update(T a) {} };