src/work/marci_property_vector.hh
changeset 17 8b29d935f1a6
child 19 3151a1026db9
equal deleted inserted replaced
-1:000000000000 0:14f6858fd308
       
     1 #ifndef MARCI_PROPERTY_VECTOR_HH
       
     2 #define MARCI_PROPERTY_VECTOR_HH
       
     3 
       
     4 #include <vector>
       
     5 
       
     6 #include <marci_graph_traits.hh>
       
     7 
       
     8 namespace marci {
       
     9 
       
    10   template <typename iterator>
       
    11   int number_of(iterator _it) { 
       
    12     int i=0;
       
    13     for( ; _it.is_valid(); ++_it) { ++i; } 
       
    14     return i;
       
    15   }
       
    16   
       
    17   template <typename graph_type, typename T>
       
    18   class node_property_vector {
       
    19     typedef typename graph_traits<graph_type>::node_iterator node_iterator;
       
    20     typedef typename graph_traits<graph_type>::each_node_iterator each_node_iterator;
       
    21     graph_type& G; 
       
    22     std::vector<T> container;
       
    23   public:
       
    24     node_property_vector(graph_type& _G) : G(_G) {
       
    25       int i=0;
       
    26       for(each_node_iterator it=G.first_node(); it.is_valid(); ++it) ++i;
       
    27       container.resize(i); 
       
    28     }
       
    29     node_property_vector(graph_type& _G, T a) : G(_G) {
       
    30       for(each_node_iterator it=G.first_node(); it.is_valid(); ++it) { container.push_back(a); }
       
    31     }
       
    32     void put(node_iterator nit, const T& a) { container[G.id(nit)]=a; }
       
    33     T get(node_iterator nit) { return container[G.id(nit)]; }
       
    34   };
       
    35 
       
    36   template <typename graph_type, typename T>
       
    37   class edge_property_vector {
       
    38     typedef typename graph_traits<graph_type>::edge_iterator edge_iterator;
       
    39     typedef typename graph_traits<graph_type>::each_edge_iterator each_edge_iterator;
       
    40     graph_type& G; 
       
    41     std::vector<T> container;
       
    42   public:
       
    43     edge_property_vector(graph_type& _G) : G(_G) {
       
    44       int i=0;
       
    45       for(each_edge_iterator it=G.first_edge(); it.is_valid(); ++it) ++i;
       
    46       container.resize(i); 
       
    47     }
       
    48     edge_property_vector(graph_type& _G, T a) : G(_G) {
       
    49       for(each_edge_iterator it=G.first_edge(); it.is_valid(); ++it) { 
       
    50 	container.push_back(a); 
       
    51       }
       
    52     }
       
    53     void put(edge_iterator eit, const T& a) { container[G.id(eit)]=a; }
       
    54     T get(edge_iterator eit) { return container[G.id(eit)]; }
       
    55   };
       
    56 
       
    57 } // namespace marci
       
    58 
       
    59 #endif //MARCI_PROPERTY_VECTOR_HH