COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci_property_vector.hh @ 188:ad1417e74042

Last change on this file since 188:ad1417e74042 was 107:8d62f0072ff0, checked in by Alpar Juttner, 18 years ago

marci -> hugo
resize -> update

File size: 1.7 KB
RevLine 
[9]1#ifndef MARCI_PROPERTY_VECTOR_HH
2#define MARCI_PROPERTY_VECTOR_HH
3
4#include <vector>
5
[107]6namespace hugo {
[9]7
8  template <typename iterator>
9  int number_of(iterator _it) {
10    int i=0;
[19]11    for( ; _it.valid(); ++_it) { ++i; }
[9]12    return i;
13  }
14 
15  template <typename graph_type, typename T>
16  class node_property_vector {
[107]17    typedef typename graph_type::node_iterator node_iterator;
18    typedef typename graph_type::each_node_iterator each_node_iterator;
[9]19    graph_type& G;
20    std::vector<T> container;
21  public:
22    node_property_vector(graph_type& _G) : G(_G) {
23      int i=0;
[19]24      for(each_node_iterator it=G.first_node(); it.valid(); ++it) ++i;
[9]25      container.resize(i);
26    }
27    node_property_vector(graph_type& _G, T a) : G(_G) {
[19]28      for(each_node_iterator it=G.first_node(); it.valid(); ++it) { container.push_back(a); }
[9]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 {
[19]36    typedef typename graph_type::edge_iterator edge_iterator;
37    typedef typename graph_type::each_edge_iterator each_edge_iterator;
[9]38    graph_type& G;
39    std::vector<T> container;
40  public:
41    edge_property_vector(graph_type& _G) : G(_G) {
42      int i=0;
[19]43      for(each_edge_iterator it=G.first_edge(); it.valid(); ++it) ++i;
[9]44      container.resize(i);
45    }
46    edge_property_vector(graph_type& _G, T a) : G(_G) {
[19]47      for(each_edge_iterator it=G.first_edge(); it.valid(); ++it) {
[9]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
[107]55} // namespace hugo
[9]56
57#endif //MARCI_PROPERTY_VECTOR_HH
Note: See TracBrowser for help on using the repository browser.