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