EdgeSet is more or less working.
authoralpar
Fri, 07 May 2004 15:58:45 +0000
changeset 579859f8c7e2a40
parent 578 159f1cbf8a45
child 580 a00f9f1cfab8
EdgeSet is more or less working.
src/hugo/list_graph.h
src/hugo/smart_graph.h
src/test/graph_test.cc
     1.1 --- a/src/hugo/list_graph.h	Fri May 07 13:27:16 2004 +0000
     1.2 +++ b/src/hugo/list_graph.h	Fri May 07 15:58:45 2004 +0000
     1.3 @@ -94,9 +94,6 @@
     1.4      class OutEdgeIt;
     1.5      class InEdgeIt;
     1.6      
     1.7 -    template <typename T> class NodeMap;
     1.8 -    template <typename T> class EdgeMap;
     1.9 -    
    1.10    public:
    1.11  
    1.12      ListGraph() : nodes(), first_node(-1),
    1.13 @@ -328,6 +325,8 @@
    1.14        NodeIt() : Node() { }
    1.15        NodeIt(Invalid i) : Node(i) { }
    1.16        NodeIt(const ListGraph& G) : Node(G.first_node) { }
    1.17 +      ///\todo Undocumented conversion Node -\> NodeIt.
    1.18 +      NodeIt(const ListGraph& G, const Node &n) : Node(n) { }
    1.19      };
    1.20  
    1.21      class Edge {
    1.22 @@ -482,6 +481,7 @@
    1.23      
    1.24      template <typename T> class EdgeMap : public DynMapBase<Edge>
    1.25      {
    1.26 +    protected:
    1.27        std::vector<T> container;
    1.28  
    1.29      public:
    1.30 @@ -944,8 +944,12 @@
    1.31      class NodeIt : public Node {
    1.32        friend class NodeSet;
    1.33      public:
    1.34 +      NodeIt() : Node() { }
    1.35 +      NodeIt(Invalid i) : Node(i) { }
    1.36        NodeIt(const NodeSet& G) : Node(G.first_node) { }
    1.37 -      NodeIt() : Node() { }
    1.38 +      ///\todo Undocumented conversion Node -\> NodeIt.
    1.39 +      NodeIt(const NodeSet& G, const Node &n) : Node(n) { }
    1.40 +
    1.41      };
    1.42  
    1.43      class Edge {
    1.44 @@ -1182,6 +1186,10 @@
    1.45        NodeIt(const EdgeSet& _G) : NodeGraphType::NodeIt(_G.G) { }
    1.46        NodeIt(const typename NodeGraphType::NodeIt &n)
    1.47  	: NodeGraphType::NodeIt(n) {}
    1.48 +      ///\todo Undocumented conversion Node -\> NodeIt.
    1.49 +      NodeIt(const EdgeSet& _G, const Node &n)
    1.50 +	: NodeGraphType::NodeIt(_G.G,n) { }
    1.51 +
    1.52        operator Node() { return Node(*this);}
    1.53      };
    1.54  
    1.55 @@ -1326,8 +1334,8 @@
    1.56  	it.n=edges[it.n].next_in;
    1.57        }
    1.58        else {
    1.59 -	NodeIt n;
    1.60 -	for(n=next(edges[it.n].head);
    1.61 +	NodeIt n(*this,edges[it.n].head);
    1.62 +	for(n=next(n);
    1.63  	    valid(n) && nodes[n].first_in == -1;
    1.64  	    next(n)) ;
    1.65  	it.n = (valid(n))?-1:nodes[n].first_in;
    1.66 @@ -1338,7 +1346,7 @@
    1.67      int id(Edge e) const { return e.n; }
    1.68  
    1.69      /// Adds a new node to the graph.
    1.70 -    Node addNode() { return G.AddNode(); }
    1.71 +    Node addNode() { return G.addNode(); }
    1.72      
    1.73      Edge addEdge(Node u, Node v) {
    1.74        int n;
    1.75 @@ -1409,6 +1417,13 @@
    1.76      
    1.77      void erase(Edge e) { eraseEdge(e.n); }
    1.78  
    1.79 +    ///Clear all edges. (Doesn't clear the nodes!)
    1.80 +    void clear() {
    1.81 +      edges.clear();
    1.82 +      first_free_edge=-1;
    1.83 +    }
    1.84 +
    1.85 +
    1.86  //     //\bug Dynamic maps must be updated!
    1.87  //     //
    1.88  //     void clear() {
    1.89 @@ -1416,17 +1431,22 @@
    1.90  //       first_node=first_free_node=first_free_edge=-1;
    1.91  //     }
    1.92  
    1.93 +  public:
    1.94 +    template <typename T> class EdgeMap;
    1.95 +    
    1.96 +    ///
    1.97      class Edge {
    1.98 +    public:
    1.99        friend class EdgeSet;
   1.100        template <typename T> friend class EdgeMap;
   1.101  
   1.102 -      //template <typename T> friend class SymEdgeSet::SymEdgeMap;      
   1.103 -      //friend Edge SymEdgeSet::opposite(Edge) const;
   1.104 -      
   1.105        friend class Node;
   1.106        friend class NodeIt;
   1.107 +    public:
   1.108 +      ///\bug It shoud be at least protected
   1.109 +      ///
   1.110 +      int n;
   1.111      protected:
   1.112 -      int n;
   1.113        friend int EdgeSet::id(Edge e) const;
   1.114  
   1.115        Edge(int nn) {n=nn;}
   1.116 @@ -1444,6 +1464,9 @@
   1.117      
   1.118      class EdgeIt : public Edge {
   1.119        friend class EdgeSet;
   1.120 +      template <typename T> friend class EdgeMap;
   1.121 +    
   1.122 +      
   1.123      public:
   1.124        EdgeIt(const EdgeSet& G) : Edge() {
   1.125  	//      	typename NodeGraphType::Node m;
   1.126 @@ -1466,7 +1489,7 @@
   1.127        OutEdgeIt() : Edge() { }
   1.128        OutEdgeIt (Invalid i) : Edge(i) { }
   1.129  
   1.130 -      OutEdgeIt(const EdgeSet& G,const Node v) : Edge(nodes[v].first_out) { }
   1.131 +      OutEdgeIt(const EdgeSet& G,const Node v) : Edge(G.nodes[v].first_out) { }
   1.132      };
   1.133      
   1.134      class InEdgeIt : public Edge {
   1.135 @@ -1474,30 +1497,35 @@
   1.136      public: 
   1.137        InEdgeIt() : Edge() { }
   1.138        InEdgeIt (Invalid i) : Edge(i) { }
   1.139 -      InEdgeIt(const EdgeSet& G,Node v) :Edge(nodes[v].first_in) { }
   1.140 +      InEdgeIt(const EdgeSet& G,Node v) :Edge(G.nodes[v].first_in) { }
   1.141      };
   1.142  
   1.143      template <typename T> class NodeMap : 
   1.144        public NodeGraphType::template NodeMap<T>
   1.145      {
   1.146 +      //This is a must, the constructors need it.
   1.147 +      typedef typename NodeGraphType::template NodeMap<T> ParentNodeMap;
   1.148      public:
   1.149 -      NodeMap(const EdgeSet &_G) :
   1.150 -        NodeGraphType::NodeMap(_G.G) { } //AJAJJ <T> would be wrong!!!
   1.151 -      NodeMap(const EdgeSet &_G,const T &t) :
   1.152 -	NodeGraphType::NodeMap(_G.G,t) { }
   1.153 +      NodeMap(const EdgeSet &_G) : ParentNodeMap(_G.G) { }
   1.154 +      NodeMap(const EdgeSet &_G,const T &t) : ParentNodeMap(_G.G,t) { }
   1.155        //It is unnecessary
   1.156        NodeMap(const typename NodeGraphType::template NodeMap<T> &m) :
   1.157 -	NodeGraphType::NodeMap(m) { }
   1.158 +	ParentNodeMap(m) { }
   1.159  
   1.160        ///\todo It can copy between different types.
   1.161        ///
   1.162        template<typename TT>
   1.163        NodeMap(const typename NodeGraphType::template NodeMap<TT> &m)
   1.164 -	: NodeGraphType::NodeMap(m) { }
   1.165 +	: ParentNodeMap(m) { }
   1.166      };
   1.167      
   1.168 +    ///
   1.169      template <typename T> class EdgeMap : public DynMapBase<Edge>
   1.170      {
   1.171 +    protected:
   1.172 +    public:
   1.173 +      ///\bug It should be at least protected
   1.174 +      ///
   1.175        std::vector<T> container;
   1.176  
   1.177      public:
   1.178 @@ -1557,12 +1585,18 @@
   1.179        }
   1.180        void erase(const Edge) { }
   1.181        
   1.182 -      void set(Edge n, T a) { container[n.n]=a; }
   1.183 +      ///\bug This doesn't work. Why?
   1.184 +      ///      void set(Edge n, T a) { container[n.n]=a; }
   1.185 +      void set(Edge n, T a) { container[G->id(n)]=a; }
   1.186        //T get(Edge n) const { return container[n.n]; }
   1.187        typename std::vector<T>::reference
   1.188 -      operator[](Edge n) { return container[n.n]; }
   1.189 +      ///\bug This doesn't work. Why?
   1.190 +      ///      operator[](Edge n) { return container[n.n]; }
   1.191 +      operator[](Edge n) { return container[G->id(n)]; }
   1.192        typename std::vector<T>::const_reference
   1.193 -      operator[](Edge n) const { return container[n.n]; }
   1.194 +      ///\bug This doesn't work. Why?
   1.195 +      ///      operator[](Edge n) const { return container[n.n]; }
   1.196 +      operator[](Edge n) const { return container[G->id(n)]; }
   1.197  
   1.198        ///\warning There is no safety check at all!
   1.199        ///Using operator = between maps attached to different graph may
   1.200 @@ -1574,6 +1608,9 @@
   1.201  	container = m.container;
   1.202  	return *this;
   1.203        }
   1.204 +      
   1.205 +      template<typename TT> friend class EdgeMap;
   1.206 +
   1.207        template<typename TT>
   1.208        const EdgeMap<T>& operator=(const EdgeMap<TT> &m)
   1.209        {
   1.210 @@ -1587,8 +1624,8 @@
   1.211  
   1.212    };
   1.213  
   1.214 -  template< typename GG>
   1.215 -  int EdgeSet<GG>::id(Node v) const { return G.id(v); }
   1.216 +  template<typename GG>
   1.217 +  inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
   1.218  
   1.219  /// @}  
   1.220  
     2.1 --- a/src/hugo/smart_graph.h	Fri May 07 13:27:16 2004 +0000
     2.2 +++ b/src/hugo/smart_graph.h	Fri May 07 15:58:45 2004 +0000
     2.3 @@ -220,6 +220,8 @@
     2.4        NodeIt() : Node() { }
     2.5        NodeIt(Invalid i) : Node(i) { }
     2.6        NodeIt(const SmartGraph& G) : Node(G.nodes.size()?0:-1) { }
     2.7 +      ///\todo Undocumented conversion Node -\> NodeIt.
     2.8 +      NodeIt(const SmartGraph& G, const Node &n) : Node(n) { }
     2.9      };
    2.10  
    2.11      class Edge {
     3.1 --- a/src/test/graph_test.cc	Fri May 07 13:27:16 2004 +0000
     3.2 +++ b/src/test/graph_test.cc	Fri May 07 15:58:45 2004 +0000
     3.3 @@ -245,8 +245,9 @@
     3.4  template void checkCompile<ListGraph>(ListGraph &);
     3.5  template void checkCompile<SymListGraph>(SymListGraph &);
     3.6  
     3.7 -//Due to some mysterious and some conceptual problems it does not work.
     3.8 -//template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
     3.9 +//Due to some mysterious problems it does not work.
    3.10 +template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
    3.11 +//template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
    3.12  
    3.13  int main() 
    3.14  {
    3.15 @@ -278,4 +279,5 @@
    3.16  
    3.17    std::cout << __FILE__ ": All tests passed.\n";
    3.18  
    3.19 +  return 0;
    3.20  }