diff -r ce9438c5a82d -r 4297098d9677 src/hugo/smart_graph.h --- a/src/hugo/smart_graph.h Wed Aug 25 18:55:57 2004 +0000 +++ b/src/hugo/smart_graph.h Mon Aug 30 12:01:47 2004 +0000 @@ -121,12 +121,6 @@ Node tail(Edge e) const { return edges[e.n].tail; } Node head(Edge e) const { return edges[e.n].head; } - Node aNode(OutEdgeIt e) const { return edges[e.n].tail; } - Node aNode(InEdgeIt e) const { return edges[e.n].head; } - - Node bNode(OutEdgeIt e) const { return edges[e.n].head; } - Node bNode(InEdgeIt e) const { return edges[e.n].tail; } - NodeIt& first(NodeIt& v) const { v=NodeIt(*this); return v; } EdgeIt& first(EdgeIt& e) const { @@ -136,41 +130,6 @@ InEdgeIt& first(InEdgeIt& e, const Node v) const { e=InEdgeIt(*this,v); return e; } -// template< typename It > -// It first() const { It e; first(e); return e; } - -// template< typename It > -// It first(Node v) const { It e; first(e,v); return e; } - - static bool valid(Edge e) { return e.n!=-1; } - static bool valid(Node n) { return n.n!=-1; } - - ///\deprecated Use - ///\code - /// e=INVALID; - ///\endcode - ///instead. - static void setInvalid(Edge &e) { e.n=-1; } - ///\deprecated Use - ///\code - /// e=INVALID; - ///\endcode - ///instead. - static void setInvalid(Node &n) { 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)%(nodes.size()+1)-1; - return it; - } - OutEdgeIt& next(OutEdgeIt& it) const - { it.n=edges[it.n].next_out; return it; } - InEdgeIt& next(InEdgeIt& it) const - { it.n=edges[it.n].next_in; return it; } - EdgeIt& next(EdgeIt& it) const { --it.n; return it; } - static int id(Node v) { return v.n; } static int id(Edge e) { return e.n; } @@ -197,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 { @@ -218,16 +193,24 @@ bool operator==(const Node i) const {return n==i.n;} bool operator!=(const Node i) const {return n!=i.n;} bool operator<(const Node i) const {return n NodeIt. - NodeIt(const SmartGraph& G, const Node &n) : Node(n) { } + NodeIt(const SmartGraph& _G) : Node(_G.nodes.size()?0:-1), G(&_G) { } + NodeIt &operator++() { + n=(n+2)%(G->nodes.size()+1)-1; + return *this; + } +// ///Validity check +// operator bool() { return Node::operator bool(); } }; class Edge { @@ -257,36 +240,54 @@ ///\bug This is a workaround until somebody tells me how to ///make class \c SymSmartGraph::SymEdgeMap friend of Edge int &idref() {return n;} - const int &idref() const {return n;} - }; + const int &idref() const {return n;} +// ///Validity check +// operator bool() { return n!=-1; } + }; class EdgeIt : public Edge { + const SmartGraph *G; friend class SmartGraph; public: - EdgeIt(const SmartGraph& G) : Edge(G.edges.size()-1) { } + EdgeIt(const SmartGraph& _G) : Edge(_G.edges.size()-1), G(&_G) { } + EdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { } EdgeIt (Invalid i) : Edge(i) { } EdgeIt() : Edge() { } ///\bug This is a workaround until somebody tells me how to ///make class \c SymSmartGraph::SymEdgeMap friend of Edge int &idref() {return n;} + EdgeIt &operator++() { --n; return *this; } +// ///Validity check +// operator bool() { return Edge::operator bool(); } }; class OutEdgeIt : public Edge { + const SmartGraph *G; friend class SmartGraph; public: OutEdgeIt() : Edge() { } + OutEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { } OutEdgeIt (Invalid i) : Edge(i) { } - OutEdgeIt(const SmartGraph& G,const Node v) - : Edge(G.nodes[v.n].first_out) {} + OutEdgeIt(const SmartGraph& _G,const Node v) + : Edge(_G.nodes[v.n].first_out), G(&_G) {} + OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; } +// ///Validity check +// operator bool() { return Edge::operator bool(); } }; class InEdgeIt : public Edge { + const SmartGraph *G; friend class SmartGraph; public: InEdgeIt() : Edge() { } + InEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { } InEdgeIt (Invalid i) : Edge(i) { } - InEdgeIt(const SmartGraph& G,Node v) :Edge(G.nodes[v.n].first_in){} + InEdgeIt(const SmartGraph& _G,Node v) + : Edge(_G.nodes[v.n].first_in), G(&_G) { } + InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; } +// ///Validity check +// operator bool() { return Edge::operator bool(); } }; template class NodeMap : public DynMapBase