[Lemon-commits] [lemon_svn] alpar: r1036 - in hugo/branches/hugo++/src: hugo test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:42:52 CET 2006
Author: alpar
Date: Tue Aug 24 17:49:42 2004
New Revision: 1036
Modified:
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:
CAUTION: hugo++ branch is in transitional state! It does not compile.
- list_graph.h, smart_graph.h conversion finished, but
- EdgeSet::EdgeIt::operator++ is still unimplemented.
- Many deprecated features removed:
valid(), setInvalid(), aNode(), bNode()
- {Node,NodeIt,Edge,...}::operator bool() removed
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 Tue Aug 24 17:49:42 2004
@@ -131,12 +131,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 {
@@ -146,36 +140,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; }
- static bool valid(Node n) { return n; }
-
- ///\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); }
-
- 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; }
@@ -317,8 +281,8 @@
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; }
+ // ///Validity check
+ // operator bool() { return n!=-1; }
};
class NodeIt : public Node {
@@ -334,8 +298,8 @@
n=G->nodes[n].next;
return *this;
}
- ///Validity check
- operator bool() { return Node::operator bool(); }
+ // ///Validity check
+ // operator bool() { return Node::operator bool(); }
};
class Edge {
@@ -367,8 +331,8 @@
///make class \c SymListGraph::SymEdgeMap friend of Edge
int &idref() {return n;}
const int &idref() const {return n;}
- ///Validity check
- operator bool() { return n!=-1; }
+ // ///Validity check
+ // operator bool() { return n!=-1; }
};
class EdgeIt : public Edge {
@@ -389,16 +353,16 @@
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;
+ 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(); }
+ // ///Validity check
+ // operator bool() { return Edge::operator bool(); }
};
class OutEdgeIt : public Edge {
@@ -411,8 +375,8 @@
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(); }
+ // ///Validity check
+ // operator bool() { return Edge::operator bool(); }
};
class InEdgeIt : public Edge {
@@ -424,8 +388,8 @@
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(); }
+ // ///Validity check
+ // operator bool() { return Edge::operator bool(); }
};
template <typename T> class NodeMap : public DynMapBase<Node>
@@ -865,12 +829,6 @@
Node tail(Edge e) const { return INVALID; }
Node head(Edge e) const { return INVALID; }
- Node aNode(OutEdgeIt e) const { return INVALID; }
- Node aNode(InEdgeIt e) const { return INVALID; }
-
- Node bNode(OutEdgeIt e) const { return INVALID; }
- Node bNode(InEdgeIt e) const { return INVALID; }
-
NodeIt& first(NodeIt& v) const {
v=NodeIt(*this); return v; }
EdgeIt& first(EdgeIt& e) const {
@@ -880,39 +838,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; }
-
- bool valid(Edge e) const { return false; }
- bool valid(Node n) const { return 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> It getNext(It it) const
- { It tmp(it); return next(tmp); }
-
- NodeIt& next(NodeIt& it) const {
- it.n=nodes[it.n].next;
- return it;
- }
- OutEdgeIt& next(OutEdgeIt& it) const { return it; }
- InEdgeIt& next(InEdgeIt& it) const { return it; }
- EdgeIt& next(EdgeIt& it) const { return it; }
-
int id(Node v) const { return v.n; }
int id(Edge e) const { return -1; }
@@ -999,7 +924,10 @@
NodeIt(const NodeSet& G) : Node(G.first_node) { }
///\todo Undocumented conversion Node -\> NodeIt.
NodeIt(const NodeSet& G, const Node &n) : Node(n) { }
-
+ NodeIt &operator++() {
+ n=G->nodes[n].next;
+ return *this;
+ }
};
class Edge {
@@ -1035,6 +963,7 @@
///\bug This is a workaround until somebody tells me how to
///make class \c SymNodeSet::SymEdgeMap friend of Edge
// int idref() {return -1;}
+ EdgeIt operator++() { return INVALID; }
};
class OutEdgeIt : public Edge {
@@ -1043,6 +972,7 @@
OutEdgeIt() : Edge() { }
OutEdgeIt (Invalid i) : Edge(i) { }
OutEdgeIt(const NodeSet& G,const Node v) : Edge() {}
+ OutEdgeIt operator++() { return INVALID; }
};
class InEdgeIt : public Edge {
@@ -1051,6 +981,7 @@
InEdgeIt() : Edge() { }
InEdgeIt (Invalid i) : Edge(i) { }
InEdgeIt(const NodeSet& G,Node v) :Edge() {}
+ InEdgeIt operator++() { return INVALID; }
};
template <typename T> class NodeMap : public DynMapBase<Node>
@@ -1245,6 +1176,8 @@
: NodeGraphType::NodeIt(_G.G,n) { }
operator Node() { return Node(*this);}
+ NodeIt &operator++() { return this->NodeGraphType::NodeIt::operator++();}
+ }
};
private:
@@ -1348,12 +1281,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 {
@@ -1363,40 +1290,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; }
-
- bool valid(Edge e) const { return e.n!=-1; }
- bool valid(Node n) const { return G.valid(n); }
-
- void setInvalid(Edge &e) { e.n=-1; }
- void setInvalid(Node &n) { G.setInvalid(n); }
-
- template <typename It> It getNext(It it) const
- { It tmp(it); return next(tmp); }
-
- NodeIt& next(NodeIt& it) const { G.next(it); 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 {
- NodeIt n(*this,edges[it.n].head);
- for(n=next(n);
- valid(n) && nodes[n].first_in == -1;
- next(n)) ;
- it.n = (valid(n))?-1:nodes[n].first_in;
- }
- return it;
- }
-
int id(Edge e) const { return e.n; }
/// Adds a new node to the graph.
@@ -1497,7 +1390,7 @@
friend class Node;
friend class NodeIt;
public:
- ///\bug It shoud be at least protected
+ ///\bug It should be at least protected
///
int n;
protected:
@@ -1526,13 +1419,20 @@
// typename NodeGraphType::Node m;
NodeIt m;
for(G.first(m);
- G.valid(m) && G.nodes[m].first_in == -1; G.next(m));
- //AJJAJ! This is a non sense!!!!!!!
- this->n = G.valid(m)?-1:G.nodes[m].first_in;
+ m!=INVALID && G.nodes[m].first_in == -1; G.next(m));
+ ///\bug AJJAJ! This is a non sense!!!!!!!
+ this->n = m!=INVALID?-1:G.nodes[m].first_in;
}
EdgeIt (Invalid i) : Edge(i) { }
EdgeIt() : Edge() { }
- ///\bug This is a workaround until somebody tells me how to
+ ///.
+
+ ///\bug UNIMPLEMENTED!!!!!
+ //
+ EdgeIt &operator++() {
+ return *this;
+ }
+ ///\bug This is a workaround until somebody tells me how to
///make class \c SymEdgeSet::SymEdgeMap friend of Edge
int &idref() {return this->n;}
};
@@ -1544,6 +1444,7 @@
OutEdgeIt (Invalid i) : Edge(i) { }
OutEdgeIt(const EdgeSet& G,const Node v) : Edge(G.nodes[v].first_out) { }
+ OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
};
class InEdgeIt : public Edge {
@@ -1552,6 +1453,7 @@
InEdgeIt() : Edge() { }
InEdgeIt (Invalid i) : Edge(i) { }
InEdgeIt(const EdgeSet& G,Node v) :Edge(G.nodes[v].first_in) { }
+ InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
};
template <typename T> class NodeMap :
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 Tue Aug 24 17:49:42 2004
@@ -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,37 +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; }
- static bool valid(Node n) { return n; }
-
- ///\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); }
-
- 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; }
@@ -214,8 +177,8 @@
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; }
+ // ///Validity check
+ // operator bool() { return n!=-1; }
};
class NodeIt : public Node {
@@ -231,8 +194,8 @@
n=(n+2)%(G->nodes.size()+1)-1;
return *this;
}
- ///Validity check
- operator bool() { return Node::operator bool(); }
+// ///Validity check
+// operator bool() { return Node::operator bool(); }
};
class Edge {
@@ -263,8 +226,8 @@
///make class \c SymSmartGraph::SymEdgeMap friend of Edge
int &idref() {return n;}
const int &idref() const {return n;}
- ///Validity check
- operator bool() { return n!=-1; }
+// ///Validity check
+// operator bool() { return n!=-1; }
};
class EdgeIt : public Edge {
@@ -278,8 +241,8 @@
///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(); }
+// ///Validity check
+// operator bool() { return Edge::operator bool(); }
};
class OutEdgeIt : public Edge {
@@ -292,8 +255,8 @@
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(); }
+// ///Validity check
+// operator bool() { return Edge::operator bool(); }
};
class InEdgeIt : public Edge {
@@ -305,8 +268,8 @@
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(); }
+// ///Validity check
+// operator bool() { return Edge::operator bool(); }
};
template <typename T> class NodeMap : public DynMapBase<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 Tue Aug 24 17:49:42 2004
@@ -6,12 +6,15 @@
#include"test_tools.h"
-/*
+/**
+\file
This test makes consistency checks of list graph structures.
-G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
+G.addNode(), G.addEdge(), G.tail(), G.head()
\todo Checks for empty graphs and isolated points.
+\todo Checks for Node->NodeIt, Edge->{EdgeIt,InEdgeIt,OutEdgeIt}
+conversion.
*/
using namespace hugo;
@@ -29,15 +32,19 @@
{
Node i; Node j(i); Node k(INVALID);
i=j;
- bool b=G.valid(i); b=b;
+ // bool b=G.valid(i); b=b;
+ bool b; b=b;
+ b=(i==INVALID); b=(i!=INVALID);
b=(i==j); b=(i!=j); b=(i<j);
}
{
NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
i=j;
j=G.first(i);
- j=G.next(i);
- bool b=G.valid(i); b=b;
+ j=++i;
+ // bool b=G.valid(i); b=b;
+ bool b; b=b;
+ b=(i==INVALID); b=(i!=INVALID);
Node n(i);
n=i;
b=(i==j); b=(i!=j); b=(i<j);
@@ -45,15 +52,19 @@
{
Edge i; Edge j(i); Edge k(INVALID);
i=j;
- bool b=G.valid(i); b=b;
+ // bool b=G.valid(i); b=b;
+ bool b; b=b;
+ b=(i==INVALID); b=(i!=INVALID);
b=(i==j); b=(i!=j); b=(i<j);
}
{
EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
i=j;
j=G.first(i);
- j=G.next(i);
- bool b=G.valid(i); b=b;
+ j=++i;
+ // bool b=G.valid(i); b=b;
+ bool b; b=b;
+ b=(i==INVALID); b=(i!=INVALID);
Edge e(i);
e=i;
b=(i==j); b=(i!=j); b=(i<j);
@@ -63,8 +74,10 @@
InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
i=j;
j=G.first(i,n);
- j=G.next(i);
- bool b=G.valid(i); b=b;
+ j=++i;
+ // bool b=G.valid(i); b=b;
+ bool b; b=b;
+ b=(i==INVALID); b=(i!=INVALID);
Edge e(i);
e=i;
b=(i==j); b=(i!=j); b=(i<j);
@@ -74,8 +87,10 @@
OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
i=j;
j=G.first(i,n);
- j=G.next(i);
- bool b=G.valid(i); b=b;
+ j=++i;
+ // bool b=G.valid(i); b=b;
+ bool b; b=b;
+ b=(i==INVALID); b=(i!=INVALID);
Edge e(i);
e=i;
b=(i==j); b=(i!=j); b=(i<j);
@@ -186,10 +201,10 @@
{
typename Graph::NodeIt n(G);
for(int i=0;i<nn;i++) {
- check(G.valid(n),"Wrong Node list linking.");
- G.next(n);
+ check(n!=INVALID,"Wrong Node list linking.");
+ ++n;
}
- check(!G.valid(n),"Wrong Node list linking.");
+ check(n==INVALID,"Wrong Node list linking.");
}
template<class Graph> void checkEdgeList(Graph &G, int nn)
@@ -198,10 +213,10 @@
EdgeIt e(G);
for(int i=0;i<nn;i++) {
- check(G.valid(e),"Wrong Edge list linking.");
- G.next(e);
+ check(e!=INVALID,"Wrong Edge list linking.");
+ ++e;
}
- check(!G.valid(e),"Wrong Edge list linking.");
+ check(e==INVALID,"Wrong Edge list linking.");
}
template<class Graph> void checkOutEdgeList(Graph &G,
@@ -210,10 +225,10 @@
{
typename Graph::OutEdgeIt e(G,n);
for(int i=0;i<nn;i++) {
- check(G.valid(e),"Wrong OutEdge list linking.");
- G.next(e);
+ check(e!=INVALID,"Wrong OutEdge list linking.");
+ ++e;
}
- check(!G.valid(e),"Wrong OutEdge list linking.");
+ check(e==INVALID,"Wrong OutEdge list linking.");
}
template<class Graph> void checkInEdgeList(Graph &G,
@@ -222,13 +237,15 @@
{
typename Graph::InEdgeIt e(G,n);
for(int i=0;i<nn;i++) {
- check(G.valid(e),"Wrong InEdge list linking.");
- G.next(e);
+ check(e!=INVALID,"Wrong InEdge list linking.");
+ ++e;
}
- check(!G.valid(e),"Wrong InEdge list linking.");
+ check(e!=INVALID,"Wrong InEdge list linking.");
}
-//Checks head(), tail() as well;
+///\file
+///\todo Checks head(), tail() as well;
+
template<class Graph> void bidirPetersen(Graph &G)
{
typedef typename Graph::Edge Edge;
@@ -238,7 +255,7 @@
std::vector<Edge> ee;
- for(EdgeIt e(G);G.valid(e);G.next(e)) ee.push_back(e);
+ for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
G.addEdge(G.head(*p),G.tail(*p));
@@ -254,10 +271,10 @@
checkNodeList(G,10);
checkEdgeList(G,30);
- for(NodeIt n(G);G.valid(n);G.next(n)) {
+ for(NodeIt n(G);n!=INVALID;++n) {
checkInEdgeList(G,n,3);
checkOutEdgeList(G,n,3);
- G.next(n);
+ ++n;
}
}
@@ -299,8 +316,9 @@
checkPetersen(G);
}
- //\todo map tests.
- //\todo copy constr tests.
+ ///\file
+ ///\todo map tests.
+ ///\todo copy constr tests.
std::cout << __FILE__ ": All tests passed.\n";
More information about the Lemon-commits
mailing list