[Lemon-commits] [lemon_svn] alpar: r755 - in hugo/trunk/src: hugo test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:41:20 CET 2006


Author: alpar
Date: Fri May  7 17:58:45 2004
New Revision: 755

Modified:
   hugo/trunk/src/hugo/list_graph.h
   hugo/trunk/src/hugo/smart_graph.h
   hugo/trunk/src/test/graph_test.cc

Log:
EdgeSet is more or less working.

Modified: hugo/trunk/src/hugo/list_graph.h
==============================================================================
--- hugo/trunk/src/hugo/list_graph.h	(original)
+++ hugo/trunk/src/hugo/list_graph.h	Fri May  7 17:58:45 2004
@@ -94,9 +94,6 @@
     class OutEdgeIt;
     class InEdgeIt;
     
-    template <typename T> class NodeMap;
-    template <typename T> 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 <typename T> class EdgeMap : public DynMapBase<Edge>
     {
+    protected:
       std::vector<T> container;
 
     public:
@@ -944,8 +944,12 @@
     class NodeIt : public Node {
       friend class NodeSet;
     public:
-      NodeIt(const NodeSet& G) : Node(G.first_node) { }
       NodeIt() : Node() { }
+      NodeIt(Invalid i) : Node(i) { }
+      NodeIt(const NodeSet& G) : Node(G.first_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 <typename T> class EdgeMap;
+    
+    ///
     class Edge {
+    public:
       friend class EdgeSet;
       template <typename T> friend class EdgeMap;
 
-      //template <typename T> friend class SymEdgeSet::SymEdgeMap;      
-      //friend Edge SymEdgeSet::opposite(Edge) const;
-      
       friend class Node;
       friend class NodeIt;
-    protected:
+    public:
+      ///\bug It shoud be at least protected
+      ///
       int n;
+    protected:
       friend int EdgeSet::id(Edge e) const;
 
       Edge(int nn) {n=nn;}
@@ -1444,6 +1464,9 @@
     
     class EdgeIt : public Edge {
       friend class EdgeSet;
+      template <typename T> 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 <typename T> class NodeMap : 
       public NodeGraphType::template NodeMap<T>
     {
+      //This is a must, the constructors need it.
+      typedef typename NodeGraphType::template NodeMap<T> ParentNodeMap;
     public:
-      NodeMap(const EdgeSet &_G) :
-        NodeGraphType::NodeMap(_G.G) { } //AJAJJ <T> 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<T> &m) :
-	NodeGraphType::NodeMap(m) { }
+	ParentNodeMap(m) { }
 
       ///\todo It can copy between different types.
       ///
       template<typename TT>
       NodeMap(const typename NodeGraphType::template NodeMap<TT> &m)
-	: NodeGraphType::NodeMap(m) { }
+	: ParentNodeMap(m) { }
     };
     
+    ///
     template <typename T> class EdgeMap : public DynMapBase<Edge>
     {
+    protected:
+    public:
+      ///\bug It should be at least protected
+      ///
       std::vector<T> 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<T>::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<T>::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<typename TT> friend class EdgeMap;
+
       template<typename TT>
       const EdgeMap<T>& operator=(const EdgeMap<TT> &m)
       {
@@ -1587,8 +1624,8 @@
 
   };
 
-  template< typename GG>
-  int EdgeSet<GG>::id(Node v) const { return G.id(v); }
+  template<typename GG>
+  inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
 
 /// @}  
 

Modified: hugo/trunk/src/hugo/smart_graph.h
==============================================================================
--- hugo/trunk/src/hugo/smart_graph.h	(original)
+++ hugo/trunk/src/hugo/smart_graph.h	Fri May  7 17:58:45 2004
@@ -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 {

Modified: hugo/trunk/src/test/graph_test.cc
==============================================================================
--- hugo/trunk/src/test/graph_test.cc	(original)
+++ hugo/trunk/src/test/graph_test.cc	Fri May  7 17:58:45 2004
@@ -245,8 +245,9 @@
 template void checkCompile<ListGraph>(ListGraph &);
 template void checkCompile<SymListGraph>(SymListGraph &);
 
-//Due to some mysterious and some conceptual problems it does not work.
-//template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
+//Due to some mysterious problems it does not work.
+template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
+//template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
 
 int main() 
 {
@@ -278,4 +279,5 @@
 
   std::cout << __FILE__ ": All tests passed.\n";
 
+  return 0;
 }



More information about the Lemon-commits mailing list