# HG changeset patch # User alpar # Date 1083945525 0 # Node ID 859f8c7e2a40e75562e272d13b86e6c2a3775676 # Parent 159f1cbf8a4558bdfb520eca6f1e87fc353a2d0d EdgeSet is more or less working. diff -r 159f1cbf8a45 -r 859f8c7e2a40 src/hugo/list_graph.h --- a/src/hugo/list_graph.h Fri May 07 13:27:16 2004 +0000 +++ b/src/hugo/list_graph.h Fri May 07 15:58:45 2004 +0000 @@ -94,9 +94,6 @@ class OutEdgeIt; class InEdgeIt; - template class NodeMap; - template class EdgeMap; - public: ListGraph() : nodes(), first_node(-1), @@ -328,6 +325,8 @@ NodeIt() : Node() { } NodeIt(Invalid i) : Node(i) { } NodeIt(const ListGraph& G) : Node(G.first_node) { } + ///\todo Undocumented conversion Node -\> NodeIt. + NodeIt(const ListGraph& G, const Node &n) : Node(n) { } }; class Edge { @@ -482,6 +481,7 @@ template class EdgeMap : public DynMapBase { + protected: std::vector container; public: @@ -944,8 +944,12 @@ class NodeIt : public Node { friend class NodeSet; public: + NodeIt() : Node() { } + NodeIt(Invalid i) : Node(i) { } NodeIt(const NodeSet& G) : Node(G.first_node) { } - NodeIt() : Node() { } + ///\todo Undocumented conversion Node -\> NodeIt. + NodeIt(const NodeSet& G, const Node &n) : Node(n) { } + }; class Edge { @@ -1182,6 +1186,10 @@ NodeIt(const EdgeSet& _G) : NodeGraphType::NodeIt(_G.G) { } NodeIt(const typename NodeGraphType::NodeIt &n) : NodeGraphType::NodeIt(n) {} + ///\todo Undocumented conversion Node -\> NodeIt. + NodeIt(const EdgeSet& _G, const Node &n) + : NodeGraphType::NodeIt(_G.G,n) { } + operator Node() { return Node(*this);} }; @@ -1326,8 +1334,8 @@ it.n=edges[it.n].next_in; } else { - NodeIt n; - for(n=next(edges[it.n].head); + 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; @@ -1338,7 +1346,7 @@ int id(Edge e) const { return e.n; } /// Adds a new node to the graph. - Node addNode() { return G.AddNode(); } + Node addNode() { return G.addNode(); } Edge addEdge(Node u, Node v) { int n; @@ -1409,6 +1417,13 @@ void erase(Edge e) { eraseEdge(e.n); } + ///Clear all edges. (Doesn't clear the nodes!) + void clear() { + edges.clear(); + first_free_edge=-1; + } + + // //\bug Dynamic maps must be updated! // // // void clear() { @@ -1416,17 +1431,22 @@ // first_node=first_free_node=first_free_edge=-1; // } + public: + template class EdgeMap; + + /// class Edge { + public: friend class EdgeSet; template friend class EdgeMap; - //template friend class SymEdgeSet::SymEdgeMap; - //friend Edge SymEdgeSet::opposite(Edge) const; - friend class Node; friend class NodeIt; + public: + ///\bug It shoud be at least protected + /// + int n; protected: - int n; friend int EdgeSet::id(Edge e) const; Edge(int nn) {n=nn;} @@ -1444,6 +1464,9 @@ class EdgeIt : public Edge { friend class EdgeSet; + template friend class EdgeMap; + + public: EdgeIt(const EdgeSet& G) : Edge() { // typename NodeGraphType::Node m; @@ -1466,7 +1489,7 @@ OutEdgeIt() : Edge() { } OutEdgeIt (Invalid i) : Edge(i) { } - OutEdgeIt(const EdgeSet& G,const Node v) : Edge(nodes[v].first_out) { } + OutEdgeIt(const EdgeSet& G,const Node v) : Edge(G.nodes[v].first_out) { } }; class InEdgeIt : public Edge { @@ -1474,30 +1497,35 @@ public: InEdgeIt() : Edge() { } InEdgeIt (Invalid i) : Edge(i) { } - InEdgeIt(const EdgeSet& G,Node v) :Edge(nodes[v].first_in) { } + InEdgeIt(const EdgeSet& G,Node v) :Edge(G.nodes[v].first_in) { } }; template class NodeMap : public NodeGraphType::template NodeMap { + //This is a must, the constructors need it. + typedef typename NodeGraphType::template NodeMap ParentNodeMap; public: - NodeMap(const EdgeSet &_G) : - NodeGraphType::NodeMap(_G.G) { } //AJAJJ would be wrong!!! - NodeMap(const EdgeSet &_G,const T &t) : - NodeGraphType::NodeMap(_G.G,t) { } + NodeMap(const EdgeSet &_G) : ParentNodeMap(_G.G) { } + NodeMap(const EdgeSet &_G,const T &t) : ParentNodeMap(_G.G,t) { } //It is unnecessary NodeMap(const typename NodeGraphType::template NodeMap &m) : - NodeGraphType::NodeMap(m) { } + ParentNodeMap(m) { } ///\todo It can copy between different types. /// template NodeMap(const typename NodeGraphType::template NodeMap &m) - : NodeGraphType::NodeMap(m) { } + : ParentNodeMap(m) { } }; + /// template class EdgeMap : public DynMapBase { + protected: + public: + ///\bug It should be at least protected + /// std::vector container; public: @@ -1557,12 +1585,18 @@ } void erase(const Edge) { } - void set(Edge n, T a) { container[n.n]=a; } + ///\bug This doesn't work. Why? + /// void set(Edge n, T a) { container[n.n]=a; } + void set(Edge n, T a) { container[G->id(n)]=a; } //T get(Edge n) const { return container[n.n]; } typename std::vector::reference - operator[](Edge n) { return container[n.n]; } + ///\bug This doesn't work. Why? + /// operator[](Edge n) { return container[n.n]; } + operator[](Edge n) { return container[G->id(n)]; } typename std::vector::const_reference - operator[](Edge n) const { return container[n.n]; } + ///\bug This doesn't work. Why? + /// operator[](Edge n) const { return container[n.n]; } + operator[](Edge n) const { return container[G->id(n)]; } ///\warning There is no safety check at all! ///Using operator = between maps attached to different graph may @@ -1574,6 +1608,9 @@ container = m.container; return *this; } + + template friend class EdgeMap; + template const EdgeMap& operator=(const EdgeMap &m) { @@ -1587,8 +1624,8 @@ }; - template< typename GG> - int EdgeSet::id(Node v) const { return G.id(v); } + template + inline int EdgeSet::id(Node v) const { return G.id(v); } /// @} diff -r 159f1cbf8a45 -r 859f8c7e2a40 src/hugo/smart_graph.h --- a/src/hugo/smart_graph.h Fri May 07 13:27:16 2004 +0000 +++ b/src/hugo/smart_graph.h Fri May 07 15:58:45 2004 +0000 @@ -220,6 +220,8 @@ NodeIt() : Node() { } NodeIt(Invalid i) : Node(i) { } NodeIt(const SmartGraph& G) : Node(G.nodes.size()?0:-1) { } + ///\todo Undocumented conversion Node -\> NodeIt. + NodeIt(const SmartGraph& G, const Node &n) : Node(n) { } }; class Edge { diff -r 159f1cbf8a45 -r 859f8c7e2a40 src/test/graph_test.cc --- a/src/test/graph_test.cc Fri May 07 13:27:16 2004 +0000 +++ b/src/test/graph_test.cc Fri May 07 15:58:45 2004 +0000 @@ -245,8 +245,9 @@ template void checkCompile(ListGraph &); template void checkCompile(SymListGraph &); -//Due to some mysterious and some conceptual problems it does not work. -//template void checkCompile >(EdgeSet &); +//Due to some mysterious problems it does not work. +template void checkCompile >(EdgeSet &); +//template void checkCompile >(EdgeSet &); int main() { @@ -278,4 +279,5 @@ std::cout << __FILE__ ": All tests passed.\n"; + return 0; }