[Lemon-commits] [lemon_svn] alpar: r972 - hugo/branches/hugo++/src/hugo
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:42:30 CET 2006
Author: alpar
Date: Wed Jul 21 13:15:32 2004
New Revision: 972
Modified:
hugo/branches/hugo++/src/hugo/list_graph.h
hugo/branches/hugo++/src/hugo/smart_graph.h
Log:
ListGraph and SmartGraph have been updated to use ++-style iterators.
Changes:
- Node and Edge now converts to bool (validity check)
- NodeIt, EdgeIt, OutEdgeIt and InEdgeIt now have
- a pointer to the graph,
- an operator++();
- a bool conversion (validity check)
- next(XXX) and valid(XXX)
- became 'static'
- they call the operator++() and the bool conv. of the iterators,
respectively.
WARNING!!! The other classes in list_graph.h and smart_graph.h remained
unchanged!
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 Jul 21 13:15:32 2004
@@ -152,36 +152,29 @@
// 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; }
+ static bool valid(Edge e) { return e; }
+ static bool valid(Node n) { return n; }
- static void setInvalid(Edge &e) { e.n=-1; }
- static void setInvalid(Node &n) { n.n=-1; }
+ ///\deprecated Use
+ ///\code
+ /// e=INVALID;
+ ///\endcode
+ ///instead.
+ static void setInvalid(Edge &e) { e=INVALID; }
+ ///\deprecated Use
+ ///\code
+ /// e=INVALID;
+ ///\endcode
+ ///instead.
+ static void setInvalid(Node &n) { n=INVALID; }
template <typename It> static It getNext(It it)
{ It tmp(it); return next(tmp); }
- NodeIt& next(NodeIt& it) const {
- it.n=nodes[it.n].next;
- 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 {
- if(edges[it.n].next_in!=-1) {
- it.n=edges[it.n].next_in;
- }
- else {
- int n;
- for(n=nodes[edges[it.n].head].next;
- n!=-1 && nodes[n].first_in == -1;
- n = nodes[n].next) ;
- it.n = (n==-1)?-1:nodes[n].first_in;
- }
- return it;
- }
+ static NodeIt& next(NodeIt& it) { return ++it; }
+ static OutEdgeIt& next(OutEdgeIt& it) { return ++it; }
+ static InEdgeIt& next(InEdgeIt& it) { return ++it; }
+ static EdgeIt& next(EdgeIt& it) { return ++it; }
static int id(Node v) { return v.n; }
static int id(Edge e) { return e.n; }
@@ -324,16 +317,25 @@
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<i.n;}
+ ///Validity check
+ operator bool() { return n!=-1; }
};
class NodeIt : public Node {
+ const ListGraph *G;
friend class ListGraph;
public:
NodeIt() : Node() { }
NodeIt(Invalid i) : Node(i) { }
- NodeIt(const ListGraph& G) : Node(G.first_node) { }
+ NodeIt(const ListGraph& _G) : Node(_G.first_node), G(&_G) { }
///\todo Undocumented conversion Node -\> NodeIt.
- NodeIt(const ListGraph& G, const Node &n) : Node(n) { }
+ NodeIt(const ListGraph& _G, const Node &n) : Node(n), G(&_G) { }
+ NodeIt &operator++() {
+ n=G->nodes[n].next;
+ return *this;
+ }
+ ///Validity check
+ operator bool() { return Node::operator bool(); }
};
class Edge {
@@ -364,41 +366,66 @@
///\bug This is a workaround until somebody tells me how to
///make class \c SymListGraph::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 ListGraph *G;
friend class ListGraph;
public:
- EdgeIt(const ListGraph& G) : Edge() {
+ EdgeIt(const ListGraph& _G) : Edge(), G(&_G) {
int m;
- for(m=G.first_node;
- m!=-1 && G.nodes[m].first_in == -1; m = G.nodes[m].next);
- n = (m==-1)?-1:G.nodes[m].first_in;
+ for(m=_G.first_node;
+ m!=-1 && _G.nodes[m].first_in == -1; m = _G.nodes[m].next);
+ n = (m==-1)?-1:_G.nodes[m].first_in;
}
EdgeIt (Invalid i) : Edge(i) { }
EdgeIt() : Edge() { }
///\bug This is a workaround until somebody tells me how to
///make class \c SymListGraph::SymEdgeMap friend of Edge
int &idref() {return n;}
+ EdgeIt &operator++() {
+ if(G->edges[n].next_in!=-1) n=G->edges[n].next_in;
+ else {
+ int nn;
+ for(nn=G->nodes[G->edges[n].head].next;
+ nn!=-1 && G->nodes[nn].first_in == -1;
+ nn = G->nodes[nn].next) ;
+ n = (nn==-1)?-1:G->nodes[nn].first_in;
+ }
+ return *this;
+ }
+ ///Validity check
+ operator bool() { return Edge::operator bool(); }
};
class OutEdgeIt : public Edge {
+ const ListGraph *G;
friend class ListGraph;
public:
OutEdgeIt() : Edge() { }
OutEdgeIt (Invalid i) : Edge(i) { }
- OutEdgeIt(const ListGraph& G,const Node v)
- : Edge(G.nodes[v.n].first_out) {}
+ OutEdgeIt(const ListGraph& _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 ListGraph *G;
friend class ListGraph;
public:
InEdgeIt() : Edge() { }
InEdgeIt (Invalid i) : Edge(i) { }
- InEdgeIt(const ListGraph& G,Node v) :Edge(G.nodes[v.n].first_in) {}
+ InEdgeIt(const ListGraph& _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 <typename T> class NodeMap : public DynMapBase<Node>
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 Jul 21 13:15:32 2004
@@ -136,34 +136,30 @@
// 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; }
+ static bool valid(Edge e) { return e; }
+ static bool valid(Node n) { return n; }
///\deprecated Use
///\code
/// e=INVALID;
///\endcode
///instead.
- static void setInvalid(Edge &e) { e.n=-1; }
+ static void setInvalid(Edge &e) { e=INVALID; }
///\deprecated Use
///\code
/// e=INVALID;
///\endcode
///instead.
- static void setInvalid(Node &n) { n.n=-1; }
+ static void setInvalid(Node &n) { n=INVALID; }
- template <typename It> It getNext(It it) const
+ template <typename It> static It getNext(It it)
{ 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 NodeIt& next(NodeIt& it) { return ++it; }
+
+ static EdgeIt& next(EdgeIt& it) { return ++it; }
+ static OutEdgeIt& next(OutEdgeIt& it) { return ++it; }
+ static InEdgeIt& next(InEdgeIt& it) { return ++it; }
static int id(Node v) { return v.n; }
static int id(Edge e) { return e.n; }
@@ -212,16 +208,25 @@
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<i.n;}
+ ///Validity check
+ operator bool() { return n!=-1; }
};
class NodeIt : public Node {
+ const SmartGraph *G;
friend class SmartGraph;
public:
NodeIt() : Node() { }
NodeIt(Invalid i) : Node(i) { }
- NodeIt(const SmartGraph& G) : Node(G.nodes.size()?0:-1) { }
+ NodeIt(const SmartGraph& _G) : Node(_G.nodes.size()?0:-1), G(&_G) { }
///\todo Undocumented conversion Node -\> NodeIt.
- NodeIt(const SmartGraph& G, const Node &n) : Node(n) { }
+ NodeIt(const SmartGraph& _G, const Node &n) : Node(n), G(&_G) { }
+ NodeIt &operator++() {
+ n=(n+2)%(G->nodes.size()+1)-1;
+ return *this;
+ }
+ ///Validity check
+ operator bool() { return Node::operator bool(); }
};
class Edge {
@@ -251,36 +256,51 @@
///\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 (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 (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 (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 <typename T> class NodeMap : public DynMapBase<Node>
More information about the Lemon-commits
mailing list