lemon/smart_graph.h
changeset 2128 509846825ddf
parent 2123 85c6f5e82108
child 2132 783b1d583be3
     1.1 --- a/lemon/smart_graph.h	Tue Jul 11 15:50:19 2006 +0000
     1.2 +++ b/lemon/smart_graph.h	Tue Jul 11 16:09:49 2006 +0000
     1.3 @@ -97,6 +97,23 @@
     1.4      ///\sa id(Edge)
     1.5      int maxEdgeId() const { return edges.size()-1; }
     1.6  
     1.7 +    Node addNode() {
     1.8 +      Node n; n.n=nodes.size();
     1.9 +      nodes.push_back(NodeT()); //FIXME: Hmmm...
    1.10 +      return n;
    1.11 +    }
    1.12 +    
    1.13 +    Edge addEdge(Node u, Node v) {
    1.14 +      Edge e; e.n=edges.size(); edges.push_back(EdgeT()); //FIXME: Hmmm...
    1.15 +      edges[e.n].source=u.n; edges[e.n].target=v.n;
    1.16 +      edges[e.n].next_out=nodes[u.n].first_out;
    1.17 +      edges[e.n].next_in=nodes[v.n].first_in;
    1.18 +      nodes[u.n].first_out=nodes[v.n].first_in=e.n;
    1.19 +
    1.20 +      return e;
    1.21 +    }
    1.22 +
    1.23 +
    1.24      Node source(Edge e) const { return edges[e.n].source; }
    1.25      Node target(Edge e) const { return edges[e.n].target; }
    1.26  
    1.27 @@ -131,28 +148,6 @@
    1.28      /// with the given id the effect of the function is undefinied.
    1.29      static Edge edgeFromId(int id) { return Edge(id);}
    1.30  
    1.31 -    Node addNode() {
    1.32 -      Node n; n.n=nodes.size();
    1.33 -      nodes.push_back(NodeT()); //FIXME: Hmmm...
    1.34 -      return n;
    1.35 -    }
    1.36 -    
    1.37 -    Edge addEdge(Node u, Node v) {
    1.38 -      Edge e; e.n=edges.size(); edges.push_back(EdgeT()); //FIXME: Hmmm...
    1.39 -      edges[e.n].source=u.n; edges[e.n].target=v.n;
    1.40 -      edges[e.n].next_out=nodes[u.n].first_out;
    1.41 -      edges[e.n].next_in=nodes[v.n].first_in;
    1.42 -      nodes[u.n].first_out=nodes[v.n].first_in=e.n;
    1.43 -
    1.44 -      return e;
    1.45 -    }
    1.46 -
    1.47 -    void clear() {
    1.48 -      edges.clear();
    1.49 -      nodes.clear();
    1.50 -    }
    1.51 -
    1.52 -
    1.53      class Node {
    1.54        friend class SmartGraphBase;
    1.55        friend class SmartGraph;
    1.56 @@ -216,16 +211,6 @@
    1.57        edge.n = edges[edge.n].next_in;
    1.58      }
    1.59  
    1.60 -    Node _split(Node n, bool connect = true)
    1.61 -    {
    1.62 -      Node b = addNode();
    1.63 -      nodes[b.n].first_out=nodes[n.n].first_out;
    1.64 -      nodes[n.n].first_out=-1;
    1.65 -      for(int i=nodes[b.n].first_out;i!=-1;i++) edges[i].source=b.n;
    1.66 -      if(connect) addEdge(n,b);
    1.67 -      return b;
    1.68 -    }
    1.69 -
    1.70    };
    1.71  
    1.72    typedef GraphExtender<SmartGraphBase> ExtendedSmartGraphBase;
    1.73 @@ -251,6 +236,18 @@
    1.74      class Snapshot;
    1.75      friend class Snapshot;
    1.76  
    1.77 +  private:
    1.78 +    ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
    1.79 +
    1.80 +    ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
    1.81 +    ///
    1.82 +    SmartGraph(const SmartGraph &) :ExtendedSmartGraphBase() {};
    1.83 +    ///\brief Assignment of SmartGraph to another is \e not allowed.
    1.84 +    ///Use GraphCopy() instead.
    1.85 +
    1.86 +    ///Assignment of SmartGraph to another is \e not allowed.
    1.87 +    ///Use GraphCopy() instead.
    1.88 +    void operator=(const SmartGraph &) {}
    1.89    protected:
    1.90      void restoreSnapshot(const Snapshot &s)
    1.91      {
    1.92 @@ -268,6 +265,36 @@
    1.93      }    
    1.94  
    1.95    public:
    1.96 +    
    1.97 +    /// Constructor
    1.98 +    
    1.99 +    /// Constructor.
   1.100 +    ///
   1.101 +    SmartGraph() {};
   1.102 +    
   1.103 +    ///Add a new node to the graph.
   1.104 +    
   1.105 +    /// \return the new node.
   1.106 +    ///
   1.107 +    Node addNode() { return Parent::addNode(); }
   1.108 +    
   1.109 +    ///Add a new edge to the graph.
   1.110 +    
   1.111 +    ///Add a new edge to the graph with source node \c s
   1.112 +    ///and target node \c t.
   1.113 +    ///\return the new edge.
   1.114 +    Edge addEdge(const Node& s, const Node& t) { 
   1.115 +      return Parent::addEdge(s, t); 
   1.116 +    }
   1.117 +
   1.118 +    ///\e
   1.119 +    
   1.120 +    ///\bug Undocumented
   1.121 +    ///\bug Doesn't destruct the maps.
   1.122 +    void clear() {
   1.123 +      edges.clear();
   1.124 +      nodes.clear();
   1.125 +    }
   1.126  
   1.127      ///Split a node.
   1.128      
   1.129 @@ -284,12 +311,15 @@
   1.130      ///\warning This functionality cannot be used together with the Snapshot
   1.131      ///feature.
   1.132      ///\todo It could be implemented in a bit faster way.
   1.133 -    Node split(Node n, bool connect = true) 
   1.134 +    Node split(Node n, bool connect = true)
   1.135      {
   1.136 -      Node b = _split(n,connect);
   1.137 +      Node b = addNode();
   1.138 +      nodes[b.n].first_out=nodes[n.n].first_out;
   1.139 +      nodes[n.n].first_out=-1;
   1.140 +      for(int i=nodes[b.n].first_out;i!=-1;i++) edges[i].source=b.n;
   1.141 +      if(connect) addEdge(n,b);
   1.142        return b;
   1.143      }
   1.144 -  
   1.145  
   1.146      ///Class to make a snapshot of the graph and to restrore to it later.
   1.147  
   1.148 @@ -376,6 +406,24 @@
   1.149    /// \todo Snapshot hasn't been implemented yet.
   1.150    ///
   1.151    class SmartUGraph : public ExtendedSmartUGraphBase {
   1.152 +  private:
   1.153 +    ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
   1.154 +
   1.155 +    ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
   1.156 +    ///
   1.157 +    SmartUGraph(const SmartUGraph &) : ExtendedSmartUGraphBase() {};
   1.158 +    ///\brief Assignment of SmartUGraph to another is \e not allowed.
   1.159 +    ///Use UGraphCopy() instead.
   1.160 +
   1.161 +    ///Assignment of SmartUGraph to another is \e not allowed.
   1.162 +    ///Use UGraphCopy() instead.
   1.163 +    void operator=(const SmartUGraph &) {}
   1.164 +  public:
   1.165 +    /// Constructor
   1.166 +    
   1.167 +    /// Constructor.
   1.168 +    ///
   1.169 +    SmartUGraph() {}
   1.170    };
   1.171  
   1.172