[Lemon-commits] [lemon_svn] marci: r336 - in hugo/trunk/src/work: . marci
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:38:51 CET 2006
Author: marci
Date: Tue Mar 23 14:31:02 2004
New Revision: 336
Modified:
hugo/trunk/src/work/iterator_bfs_demo.cc
hugo/trunk/src/work/marci/graph_wrapper.h
Log:
.
Modified: hugo/trunk/src/work/iterator_bfs_demo.cc
==============================================================================
--- hugo/trunk/src/work/iterator_bfs_demo.cc (original)
+++ hugo/trunk/src/work/iterator_bfs_demo.cc Tue Mar 23 14:31:02 2004
@@ -261,6 +261,10 @@
cout << edge_name.get(e) << " ";
cout << endl;
}
+// for(GW::EdgeIt e=gw.first<GW::EdgeIt>(); gw.valid(e); gw.next(e)) {
+// cout << edge_name.get(e) << " ";
+// }
+// cout << endl;
cout << "bfs from t ..." << endl;
BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
Modified: hugo/trunk/src/work/marci/graph_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/graph_wrapper.h (original)
+++ hugo/trunk/src/work/marci/graph_wrapper.h Tue Mar 23 14:31:02 2004
@@ -333,27 +333,27 @@
typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt InEdgeIt;
typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OutEdgeIt;
+ RevGraphWrapper(GraphWrapper _gw) :
+ GraphWrapperSkeleton<GraphWrapper>(_gw) { }
+
Node head(const Edge& e) const
{ return GraphWrapperSkeleton<GraphWrapper>::tail(e); }
Node tail(const Edge& e) const
{ return GraphWrapperSkeleton<GraphWrapper>::head(e); }
-
- RevGraphWrapper(GraphWrapper _gw) :
- GraphWrapperSkeleton<GraphWrapper>(_gw) { }
};
-
-// template<typename Graph>
+// template<typename GraphWrapper>
// class UndirGraphWrapper {
// protected:
-// Graph* graph;
-
+// //Graph* graph;
+// GraphWrapper gw;
+
// public:
-// typedef Graph BaseGraph;
+// typedef GraphWrapper BaseGraph;
-// typedef typename Graph::Node Node;
-// typedef typename Graph::NodeIt NodeIt;
+// typedef typename GraphWrapper::Node Node;
+// typedef typename GraphWrapper::NodeIt NodeIt;
// //typedef typename Graph::Edge Edge;
// //typedef typename Graph::OutEdgeIt OutEdgeIt;
@@ -362,19 +362,19 @@
// //typedef typename Graph::EdgeIt EdgeIt;
// //private:
-// typedef typename Graph::Edge GraphEdge;
-// typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
-// typedef typename Graph::InEdgeIt GraphInEdgeIt;
+// typedef typename GraphWrapper::Edge GraphEdge;
+// typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
+// typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
// //public:
// //UndirGraphWrapper() : graph(0) { }
-// UndirGraphWrapper(Graph& _graph) : graph(&_graph) { }
+// UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
-// void setGraph(Graph& _graph) { graph = &_graph; }
-// Graph& getGraph() const { return (*graph); }
+// //void setGraph(Graph& _graph) { graph = &_graph; }
+// //Graph& getGraph() const { return (*graph); }
// class Edge {
-// friend class UndirGraphWrapper<Graph>;
+// friend class UndirGraphWrapper<GraphWrapper>;
// bool out_or_in; //true iff out
// GraphOutEdgeIt out;
// GraphInEdgeIt in;
@@ -399,58 +399,59 @@
// };
// class OutEdgeIt : public Edge {
-// friend class UndirGraphWrapper<Graph>;
+// friend class UndirGraphWrapper<GraphWrapper>;
// public:
// OutEdgeIt() : Edge() { }
// OutEdgeIt(const Invalid& i) : Edge(i) { }
-// OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() {
+// OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n)
+// : Edge() {
// out_or_in=true;
-// _G.graph->first(out, n);
-// if (!(_G.graph->valid(out))) {
+// _G.gw.first(out, n);
+// if (!(_G.gw.valid(out))) {
// out_or_in=false;
-// _G.graph->first(in, n);
+// _G.gw.first(in, n);
// }
// }
// };
// OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
// e.out_or_in=true;
-// graph->first(e.out, n);
-// if (!(graph->valid(e.out))) {
+// gw.first(e.out, n);
+// if (!(gw.valid(e.out))) {
// e.out_or_in=false;
-// graph->first(e.in, n);
+// gw.first(e.in, n);
// }
// return e;
// }
// OutEdgeIt& next(OutEdgeIt& e) const {
// if (e.out_or_in) {
-// Node n=graph->tail(e.out);
-// graph->next(e.out);
-// if (!graph->valid(e.out)) {
+// Node n=gw.tail(e.out);
+// gw.next(e.out);
+// if (!gw.valid(e.out)) {
// e.out_or_in=false;
-// graph->first(e.in, n);
+// gw.first(e.in, n);
// }
// } else {
-// graph->next(e.in);
+// gw.next(e.in);
// }
// return e;
// }
// Node aNode(const OutEdgeIt& e) const {
-// if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
+// if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
// Node bNode(const OutEdgeIt& e) const {
-// if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
+// if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
// typedef OutEdgeIt InEdgeIt;
-// template<typename I> I& first(I& i) const { return graph->first(i); }
+// template<typename I> I& first(I& i) const { return gw.first(i); }
// // template<typename I, typename P> I& first(I& i, const P& p) const {
// // return graph->first(i, p); }
// template<typename I> I getNext(const I& i) const {
-// return graph->getNext(i); }
-// template<typename I> I& next(I &i) const { return graph->next(i); }
+// return gw.getNext(i); }
+// template<typename I> I& next(I &i) const { return gw.next(i); }
// template< typename It > It first() const {
// It e; first(e); return e; }
@@ -458,76 +459,72 @@
// template< typename It > It first(const Node& v) const {
// It e; first(e, v); return e; }
-// Node head(const Edge& e) const { return graph->head(e); }
-// Node tail(const Edge& e) const { return graph->tail(e); }
+// Node head(const Edge& e) const { return gw.head(e); }
+// Node tail(const Edge& e) const { return gw.tail(e); }
// template<typename I> bool valid(const I& i) const
-// { return graph->valid(i); }
+// { return gw.valid(i); }
// //template<typename I> void setInvalid(const I &i);
// //{ return graph->setInvalid(i); }
-// int nodeNum() const { return graph->nodeNum(); }
-// int edgeNum() const { return graph->edgeNum(); }
+// int nodeNum() const { return gw.nodeNum(); }
+// int edgeNum() const { return gw.edgeNum(); }
// // template<typename I> Node aNode(const I& e) const {
// // return graph->aNode(e); }
// // template<typename I> Node bNode(const I& e) const {
// // return graph->bNode(e); }
-// Node addNode() const { return graph->addNode(); }
+// Node addNode() const { return gw.addNode(); }
// // FIXME: ez igy nem jo, mert nem
// // Edge addEdge(const Node& tail, const Node& head) const {
// // return graph->addEdge(tail, head); }
-// template<typename I> void erase(const I& i) const { graph->erase(i); }
+// template<typename I> void erase(const I& i) const { gw.erase(i); }
-// void clear() const { graph->clear(); }
+// void clear() const { gw.clear(); }
-// template<typename T> class NodeMap : public Graph::NodeMap<T> {
+// template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
// public:
-// NodeMap(const UndirGraphWrapper<Graph>& _G) :
-// Graph::NodeMap<T>(_G.getGraph()) { }
-// NodeMap(const UndirGraphWrapper<Graph>& _G, T a) :
-// Graph::NodeMap<T>(_G.getGraph(), a) { }
+// NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
+// GraphWrapper::NodeMap<T>(_G.gw) { }
+// NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
+// GraphWrapper::NodeMap<T>(_G.gw, a) { }
// };
-// template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
+// template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
// public:
-// EdgeMap(const UndirGraphWrapper<Graph>& _G) :
-// Graph::EdgeMap<T>(_G.getGraph()) { }
-// EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) :
-// Graph::EdgeMap<T>(_G.getGraph(), a) { }
+// EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
+// GraphWrapper::EdgeMap<T>(_G.gw) { }
+// EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
+// GraphWrapper::EdgeMap<T>(_G.gw, a) { }
// };
// };
template<typename GraphWrapper>
- class UndirGraphWrapper {
+ class UndirGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
protected:
- //Graph* graph;
- GraphWrapper gw;
+// GraphWrapper gw;
public:
- typedef GraphWrapper BaseGraph;
+ //typedef GraphWrapper BaseGraph;
- typedef typename GraphWrapper::Node Node;
- typedef typename GraphWrapper::NodeIt NodeIt;
-
- //typedef typename Graph::Edge Edge;
- //typedef typename Graph::OutEdgeIt OutEdgeIt;
- //typedef typename Graph::InEdgeIt InEdgeIt;
- //typedef typename Graph::SymEdgeIt SymEdgeIt;
- //typedef typename Graph::EdgeIt EdgeIt;
+ typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
+ typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
//private:
- typedef typename GraphWrapper::Edge GraphEdge;
- typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
- typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
+ typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge GraphEdge;
+ typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt GraphOutEdgeIt;
+ typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt GraphInEdgeIt;
//public:
//UndirGraphWrapper() : graph(0) { }
- UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
+ UndirGraphWrapper(GraphWrapper _gw) :
+ GraphWrapperSkeleton<GraphWrapper>(_gw) { }
+
+ //UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
//void setGraph(Graph& _graph) { graph = &_graph; }
//Graph& getGraph() const { return (*graph); }
@@ -573,6 +570,28 @@
}
};
+ typedef OutEdgeIt InEdgeIt;
+
+ class EdgeIt : public Edge {
+ friend class UndirGraphWrapper<GraphWrapper>;
+ protected:
+ NodeIt v;
+ public:
+ EdgeIt() : Edge() { }
+ EdgeIt(const Invalid& i) : Edge(i) { }
+ EdgeIt(const UndirGraphWrapper<GraphWrapper>& _G)
+ : Edge() {
+ out_or_in=true;
+ //Node v;
+ _G.first(v);
+ if (_G.valid(v)) _G.gw.first(out); else out=INVALID;
+ while (_G.valid(v) && !_G.gw.valid(out)) {
+ _G.gw.next(v);
+ if (_G.valid(v)) _G.gw.first(out);
+ }
+ }
+ };
+
OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
e.out_or_in=true;
gw.first(e.out, n);
@@ -583,6 +602,22 @@
return e;
}
+ EdgeIt& first(EdgeIt& e) const {
+ e.out_or_in=true;
+ //NodeIt v;
+ first(e.v);
+ if (valid(e.v)) gw.first(e.out, e.v); else e.out=INVALID;
+ while (valid(e.v) && !gw.valid(e.out)) {
+ gw.next(e.v);
+ if (valid(e.v)) gw.first(e.out, e.v);
+ }
+ return e;
+ }
+
+ template<typename I> I& first(I& i) const { return gw.first(i); }
+ template<typename I, typename P> I& first(I& i, const P& p) const {
+ return graph->first(i, p); }
+
OutEdgeIt& next(OutEdgeIt& e) const {
if (e.out_or_in) {
Node n=gw.tail(e.out);
@@ -597,20 +632,20 @@
return e;
}
- Node aNode(const OutEdgeIt& e) const {
- if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
- Node bNode(const OutEdgeIt& e) const {
- if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
-
- typedef OutEdgeIt InEdgeIt;
+ EdgeIt& next(EdgeIt& e) const {
+ //NodeIt v=tail(e);
+ gw.next(e.out);
+ while (valid(e.v) && !gw.valid(e.out)) {
+ next(e.v);
+ if (valid(e.v)) gw.first(e.out, e.v);
+ }
+ return e;
+ }
- template<typename I> I& first(I& i) const { return gw.first(i); }
-// template<typename I, typename P> I& first(I& i, const P& p) const {
-// return graph->first(i, p); }
+ template<typename I> I& next(I &i) const { return gw.next(i); }
template<typename I> I getNext(const I& i) const {
return gw.getNext(i); }
- template<typename I> I& next(I &i) const { return gw.next(i); }
template< typename It > It first() const {
It e; first(e); return e; }
@@ -618,48 +653,52 @@
template< typename It > It first(const Node& v) const {
It e; first(e, v); return e; }
- Node head(const Edge& e) const { return gw.head(e); }
- Node tail(const Edge& e) const { return gw.tail(e); }
+// Node head(const Edge& e) const { return gw.head(e); }
+// Node tail(const Edge& e) const { return gw.tail(e); }
- template<typename I> bool valid(const I& i) const
- { return gw.valid(i); }
+// template<typename I> bool valid(const I& i) const
+// { return gw.valid(i); }
- //template<typename I> void setInvalid(const I &i);
- //{ return graph->setInvalid(i); }
-
- int nodeNum() const { return gw.nodeNum(); }
- int edgeNum() const { return gw.edgeNum(); }
+// int nodeNum() const { return gw.nodeNum(); }
+// int edgeNum() const { return gw.edgeNum(); }
// template<typename I> Node aNode(const I& e) const {
// return graph->aNode(e); }
// template<typename I> Node bNode(const I& e) const {
// return graph->bNode(e); }
+
+ Node aNode(const OutEdgeIt& e) const {
+ if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
+ Node bNode(const OutEdgeIt& e) const {
+ if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
- Node addNode() const { return gw.addNode(); }
+// Node addNode() const { return gw.addNode(); }
+
// FIXME: ez igy nem jo, mert nem
// Edge addEdge(const Node& tail, const Node& head) const {
// return graph->addEdge(tail, head); }
- template<typename I> void erase(const I& i) const { gw.erase(i); }
+// template<typename I> void erase(const I& i) const { gw.erase(i); }
- void clear() const { gw.clear(); }
+// void clear() const { gw.clear(); }
- template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
- public:
- NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
- GraphWrapper::NodeMap<T>(_G.gw) { }
- NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
- GraphWrapper::NodeMap<T>(_G.gw, a) { }
- };
+// template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
+// public:
+// NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
+// GraphWrapper::NodeMap<T>(_G.gw) { }
+// NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
+// GraphWrapper::NodeMap<T>(_G.gw, a) { }
+// };
- template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
- public:
- EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
- GraphWrapper::EdgeMap<T>(_G.gw) { }
- EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
- GraphWrapper::EdgeMap<T>(_G.gw, a) { }
- };
- };
+// template<typename T> class EdgeMap :
+// public GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T> {
+// public:
+// EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
+// GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T>(_G.gw) { }
+// EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
+// GraphWrapper::EdgeMap<T>(_G.gw, a) { }
+// };
+ };
More information about the Lemon-commits
mailing list