src/include/smart_graph.h
changeset 348 b63ea19e502e
parent 253 f45703336699
child 353 eeae2f4a0d74
equal deleted inserted replaced
0:9f7d600caba2 1:53d2e4181817
    77     class NodeIt;
    77     class NodeIt;
    78     class EdgeIt;
    78     class EdgeIt;
    79     class OutEdgeIt;
    79     class OutEdgeIt;
    80     class InEdgeIt;
    80     class InEdgeIt;
    81     
    81     
    82     //     class Node { int n; };
       
    83     //     class NodeIt : public Node { };
       
    84     //     class Edge { int n; };
       
    85     //     class EdgeIt : public Edge {};
       
    86     //     class OutEdgeIt : public Edge {};
       
    87     //     class InEdgeIt : public Edge {};
       
    88     //     class SymEdge;
       
    89     
       
    90     template <typename T> class NodeMap;
    82     template <typename T> class NodeMap;
    91     template <typename T> class EdgeMap;
    83     template <typename T> class EdgeMap;
    92     
    84     
    93   public:
    85   public:
    94 
       
    95     /* default constructor */
       
    96 
    86 
    97     SmartGraph() : nodes(), edges() { }
    87     SmartGraph() : nodes(), edges() { }
    98     SmartGraph(const SmartGraph &_g) : nodes(_g.nodes), edges(_g.edges) { }
    88     SmartGraph(const SmartGraph &_g) : nodes(_g.nodes), edges(_g.edges) { }
    99     
    89     
   100     ~SmartGraph()
    90     ~SmartGraph()
   116     int maxEdgeId() const { return edges.size(); }  //FIXME: What is this?
   106     int maxEdgeId() const { return edges.size(); }  //FIXME: What is this?
   117 
   107 
   118     Node tail(Edge e) const { return edges[e.n].tail; }
   108     Node tail(Edge e) const { return edges[e.n].tail; }
   119     Node head(Edge e) const { return edges[e.n].head; }
   109     Node head(Edge e) const { return edges[e.n].head; }
   120 
   110 
   121     // Marci
       
   122     Node aNode(OutEdgeIt e) const { return edges[e.n].tail; }
   111     Node aNode(OutEdgeIt e) const { return edges[e.n].tail; }
   123     Node aNode(InEdgeIt e) const { return edges[e.n].head; }
   112     Node aNode(InEdgeIt e) const { return edges[e.n].head; }
   124 //     //Node aNode(const SymEdge& e) const { return e.aNode(); }
   113 
   125 
       
   126     // Marci
       
   127     Node bNode(OutEdgeIt e) const { return edges[e.n].head; }
   114     Node bNode(OutEdgeIt e) const { return edges[e.n].head; }
   128     Node bNode(InEdgeIt e) const { return edges[e.n].tail; }
   115     Node bNode(InEdgeIt e) const { return edges[e.n].tail; }
   129 //     //Node bNode(const SymEdge& e) const { return e.bNode(); }
       
   130 
   116 
   131     NodeIt& first(NodeIt& v) const { 
   117     NodeIt& first(NodeIt& v) const { 
   132       v=NodeIt(*this); return v; }
   118       v=NodeIt(*this); return v; }
   133     EdgeIt& first(EdgeIt& e) const { 
   119     EdgeIt& first(EdgeIt& e) const { 
   134       e=EdgeIt(*this); return e; }
   120       e=EdgeIt(*this); return e; }
   270     public: 
   256     public: 
   271       InEdgeIt() : Edge() { }
   257       InEdgeIt() : Edge() { }
   272       InEdgeIt (Invalid i) : Edge(i) { }
   258       InEdgeIt (Invalid i) : Edge(i) { }
   273       InEdgeIt(const SmartGraph& G,Node v) :Edge(G.nodes[v.n].first_in){}
   259       InEdgeIt(const SmartGraph& G,Node v) :Edge(G.nodes[v.n].first_in){}
   274     };
   260     };
   275 
       
   276     // Map types
       
   277 
       
   278 //     // Static Maps are not necessary.
       
   279 //     template <typename T>
       
   280 //     class NodeMap {
       
   281 //       const SmartGraph& G; 
       
   282 //       std::vector<T> container;
       
   283 //     public:
       
   284 //       typedef T ValueType;
       
   285 //       typedef Node KeyType;
       
   286 //       NodeMap(const SmartGraph& _G) : G(_G), container(G.maxNodeId()) { }
       
   287 //       NodeMap(const SmartGraph& _G, T a) : 
       
   288 // 	G(_G), container(G.maxNodeId(), a) { }
       
   289 //       void set(Node n, T a) { container[n.n]=a; }
       
   290 //       T get(Node n) const { return container[n.n]; }
       
   291 //       T& operator[](Node n) { return container[n.n]; }
       
   292 //       const T& operator[](Node n) const { return container[n.n]; }
       
   293 //       void update() { container.resize(G.maxNodeId()); }
       
   294 //       void update(T a) { container.resize(G.maxNodeId(), a); }
       
   295 //     };
       
   296 
       
   297 //     template <typename T>
       
   298 //     class EdgeMap {
       
   299 //       const SmartGraph& G; 
       
   300 //       std::vector<T> container;
       
   301 //     public:
       
   302 //       typedef T ValueType;
       
   303 //       typedef Edge KeyType;
       
   304 //       EdgeMap(const SmartGraph& _G) : G(_G), container(G.maxEdgeId()) { }
       
   305 //       EdgeMap(const SmartGraph& _G, T a) : 
       
   306 // 	G(_G), container(G.maxEdgeId(), a) { }
       
   307 //       void set(Edge e, T a) { container[e.n]=a; }
       
   308 //       T get(Edge e) const { return container[e.n]; }
       
   309 //       T& operator[](Edge e) { return container[e.n]; } 
       
   310 //       const T& operator[](Edge e) const { return container[e.n]; } 
       
   311 //       void update() { container.resize(G.maxEdgeId()); }
       
   312 //       void update(T a) { container.resize(G.maxEdgeId(), a); }
       
   313 //     };
       
   314 
   261 
   315     template <typename T> class NodeMap : public DynMapBase<Node>
   262     template <typename T> class NodeMap : public DynMapBase<Node>
   316     {
   263     {
   317       std::vector<T> container;
   264       std::vector<T> container;
   318 
   265 
   372       }
   319       }
   373 
   320 
   374       void erase(const Node) { }
   321       void erase(const Node) { }
   375       
   322       
   376       void set(Node n, T a) { container[n.n]=a; }
   323       void set(Node n, T a) { container[n.n]=a; }
   377       //T get(Node n) const { return container[n.n]; }
   324       //'T& operator[](Node n)' would be wrong here
   378       //Hajjaj:
       
   379       //T& operator[](Node n) { return container[n.n]; }
       
   380       typename std::vector<T>::reference
   325       typename std::vector<T>::reference
   381       operator[](Node n) { return container[n.n]; }
   326       operator[](Node n) { return container[n.n]; }
   382       //const T& operator[](Node n) const { return container[n.n]; }
   327       //'const T& operator[](Node n)' would be wrong here
   383       typename std::vector<T>::const_reference 
   328       typename std::vector<T>::const_reference 
   384       operator[](Node n) const { return container[n.n]; }
   329       operator[](Node n) const { return container[n.n]; }
   385 
   330 
   386       ///\warning There is no safety check at all!
   331       ///\warning There is no safety check at all!
   387       ///Using operator = between maps attached to different graph may
   332       ///Using operator = between maps attached to different graph may
   398       {
   343       {
   399 	copy(m.container.begin(), m.container.end(), container.begin());
   344 	copy(m.container.begin(), m.container.end(), container.begin());
   400 	return *this;
   345 	return *this;
   401       }
   346       }
   402       
   347       
   403       void update() {}    //Useless for DynMaps
   348       void update() {}    //Useless for Dynamic Maps
   404       void update(T a) {}  //Useless for DynMaps
   349       void update(T a) {}  //Useless for Dynamic Maps
   405     };
   350     };
   406     
   351     
   407     template <typename T> class EdgeMap : public DynMapBase<Edge>
   352     template <typename T> class EdgeMap : public DynMapBase<Edge>
   408     {
   353     {
   409       std::vector<T> container;
   354       std::vector<T> container;