src/work/list_graph.hh
changeset 69 24c2c2989e0f
parent 67 5f86199dcf3e
child 75 87623302a68f
equal deleted inserted replaced
3:e6f02f0e0ac3 4:dc08a698595c
    24     class EdgeIt;
    24     class EdgeIt;
    25     class EachEdgeIt;
    25     class EachEdgeIt;
    26     class OutEdgeIt;
    26     class OutEdgeIt;
    27     class InEdgeIt;
    27     class InEdgeIt;
    28     class SymEdgeIt;
    28     class SymEdgeIt;
    29     template <typename ValueType> class NodeMap;
    29     template <typename T> class NodeMap;
    30     template <typename ValueType> class EdgeMap;
    30     template <typename T> class EdgeMap;
    31     
    31     
    32   private:
    32   private:
    33     
    33     
    34     template <typename ValueType> friend class NodeMap;
    34     template <typename T> friend class NodeMap;
    35     template <typename ValueType> friend class EdgeMap;
    35     template <typename T> friend class EdgeMap;
    36 
    36 
    37     template <typename ValueType>
    37     template <typename T>
    38     class NodeMap {
    38     class NodeMap {
    39       const ListGraph& G; 
    39       const ListGraph& G; 
    40       std::vector<ValueType> container;
    40       std::vector<T> container;
    41     public:
    41     public:
    42       NodeMap(const ListGraph& _G) : G(_G), container(_G.node_id) { }
    42       typedef T ValueType;
    43       NodeMap(const ListGraph& _G, ValueType a) : 
    43       typedef NodeIt KeyType;
    44 	G(_G), container(_G.node_id, a) { }
    44       NodeMap(const ListGraph& _G) : G(_G), container(G.node_id) { }
    45       void set(NodeIt nit, ValueType a) { container[G.id(nit)]=a; }
    45       NodeMap(const ListGraph& _G, T a) : 
    46       ValueType get(NodeIt nit) const { return container[G.id(nit)]; }
    46 	G(_G), container(G.node_id, a) { }
    47     };
    47       void set(NodeIt nit, T a) { container[G.id(nit)]=a; }
    48 
    48       T get(NodeIt nit) const { return container[G.id(nit)]; }
    49     template <typename ValueType>
    49       void resize() { container.resize(G.node_id); }
       
    50       void resize(T a) { container.resize(G.node_id, a); }
       
    51     };
       
    52 
       
    53     template <typename T>
    50     class EdgeMap {
    54     class EdgeMap {
    51       const ListGraph& G; 
    55       const ListGraph& G; 
    52       std::vector<ValueType> container;
    56       std::vector<T> container;
    53     public:
    57     public:
    54       EdgeMap(const ListGraph& _G) : G(_G), container(_G.edge_id) { }
    58       typedef T ValueType;
    55       EdgeMap(const ListGraph& _G, ValueType a) : 
    59       typedef EdgeIt KeyType;
    56 	G(_G), container(_G.edge_id, a) { }
    60       EdgeMap(const ListGraph& _G) : G(_G), container(G.edge_id) { }
    57       void set(EdgeIt eit, ValueType a) { container[G.id(eit)]=a; }
    61       EdgeMap(const ListGraph& _G, T a) : 
    58       ValueType get(EdgeIt eit) const { return container[G.id(eit)]; }
    62 	G(_G), container(G.edge_id, a) { }
       
    63       void set(EdgeIt eit, T a) { container[G.id(eit)]=a; }
       
    64       T get(EdgeIt eit) const { return container[G.id(eit)]; }
       
    65       void resize() { container.resize(G.edge_id); }
       
    66       void resize(T a) { container.resize(G.edge_id, a); }
    59     };
    67     };
    60 
    68 
    61     int node_id;
    69     int node_id;
    62     int edge_id;
    70     int edge_id;
    63     int _node_num;
    71     int _node_num;
   299       _delete_node(i.node); 
   307       _delete_node(i.node); 
   300     }
   308     }
   301   
   309   
   302     void erase(EdgeIt e) { _delete_edge(e.edge); }
   310     void erase(EdgeIt e) { _delete_edge(e.edge); }
   303 
   311 
       
   312     void clear() { 
       
   313       while (first<EachNodeIt>().valid()) erase(first<EachNodeIt>());
       
   314     }
       
   315 
   304     void setTail(EdgeIt e, NodeIt tail) {
   316     void setTail(EdgeIt e, NodeIt tail) {
   305       _set_tail(e.edge, tail.node); 
   317       _set_tail(e.edge, tail.node); 
   306     }
   318     }
   307 
   319 
   308     void setHead(EdgeIt e, NodeIt head) {
   320     void setHead(EdgeIt e, NodeIt head) {