src/work/marci/oldies/marci_property_vector.hh
changeset 280 19f3943521ab
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/marci/oldies/marci_property_vector.hh	Sat Apr 03 14:41:31 2004 +0000
     1.3 @@ -0,0 +1,57 @@
     1.4 +#ifndef MARCI_PROPERTY_VECTOR_HH
     1.5 +#define MARCI_PROPERTY_VECTOR_HH
     1.6 +
     1.7 +#include <vector>
     1.8 +
     1.9 +namespace hugo {
    1.10 +
    1.11 +  template <typename iterator>
    1.12 +  int number_of(iterator _it) { 
    1.13 +    int i=0;
    1.14 +    for( ; _it.valid(); ++_it) { ++i; } 
    1.15 +    return i;
    1.16 +  }
    1.17 +  
    1.18 +  template <typename graph_type, typename T>
    1.19 +  class node_property_vector {
    1.20 +    typedef typename graph_type::node_iterator node_iterator;
    1.21 +    typedef typename graph_type::each_node_iterator each_node_iterator;
    1.22 +    graph_type& G; 
    1.23 +    std::vector<T> container;
    1.24 +  public:
    1.25 +    node_property_vector(graph_type& _G) : G(_G) {
    1.26 +      int i=0;
    1.27 +      for(each_node_iterator it=G.first_node(); it.valid(); ++it) ++i;
    1.28 +      container.resize(i); 
    1.29 +    }
    1.30 +    node_property_vector(graph_type& _G, T a) : G(_G) {
    1.31 +      for(each_node_iterator it=G.first_node(); it.valid(); ++it) { container.push_back(a); }
    1.32 +    }
    1.33 +    void put(node_iterator nit, const T& a) { container[G.id(nit)]=a; }
    1.34 +    T get(node_iterator nit) { return container[G.id(nit)]; }
    1.35 +  };
    1.36 +
    1.37 +  template <typename graph_type, typename T>
    1.38 +  class edge_property_vector {
    1.39 +    typedef typename graph_type::edge_iterator edge_iterator;
    1.40 +    typedef typename graph_type::each_edge_iterator each_edge_iterator;
    1.41 +    graph_type& G; 
    1.42 +    std::vector<T> container;
    1.43 +  public:
    1.44 +    edge_property_vector(graph_type& _G) : G(_G) {
    1.45 +      int i=0;
    1.46 +      for(each_edge_iterator it=G.first_edge(); it.valid(); ++it) ++i;
    1.47 +      container.resize(i); 
    1.48 +    }
    1.49 +    edge_property_vector(graph_type& _G, T a) : G(_G) {
    1.50 +      for(each_edge_iterator it=G.first_edge(); it.valid(); ++it) { 
    1.51 +	container.push_back(a); 
    1.52 +      }
    1.53 +    }
    1.54 +    void put(edge_iterator eit, const T& a) { container[G.id(eit)]=a; }
    1.55 +    T get(edge_iterator eit) { return container[G.id(eit)]; }
    1.56 +  };
    1.57 +
    1.58 +} // namespace hugo
    1.59 +
    1.60 +#endif //MARCI_PROPERTY_VECTOR_HH