author | alpar |
Mon, 16 Feb 2004 10:57:01 +0000 | |
changeset 74 | 82d3dbe912d9 |
parent 9 | a9ed3f1c2c63 |
child 107 | 8d62f0072ff0 |
permissions | -rw-r--r-- |
marci@9 | 1 |
#ifndef MARCI_PROPERTY_VECTOR_HH |
marci@9 | 2 |
#define MARCI_PROPERTY_VECTOR_HH |
marci@9 | 3 |
|
marci@9 | 4 |
#include <vector> |
marci@9 | 5 |
|
marci@9 | 6 |
namespace marci { |
marci@9 | 7 |
|
marci@9 | 8 |
template <typename iterator> |
marci@9 | 9 |
int number_of(iterator _it) { |
marci@9 | 10 |
int i=0; |
marci@19 | 11 |
for( ; _it.valid(); ++_it) { ++i; } |
marci@9 | 12 |
return i; |
marci@9 | 13 |
} |
marci@9 | 14 |
|
marci@9 | 15 |
template <typename graph_type, typename T> |
marci@9 | 16 |
class node_property_vector { |
marci@19 | 17 |
typedef typename list_graph::node_iterator node_iterator; |
marci@19 | 18 |
typedef typename list_graph::each_node_iterator each_node_iterator; |
marci@9 | 19 |
graph_type& G; |
marci@9 | 20 |
std::vector<T> container; |
marci@9 | 21 |
public: |
marci@9 | 22 |
node_property_vector(graph_type& _G) : G(_G) { |
marci@9 | 23 |
int i=0; |
marci@19 | 24 |
for(each_node_iterator it=G.first_node(); it.valid(); ++it) ++i; |
marci@9 | 25 |
container.resize(i); |
marci@9 | 26 |
} |
marci@9 | 27 |
node_property_vector(graph_type& _G, T a) : G(_G) { |
marci@19 | 28 |
for(each_node_iterator it=G.first_node(); it.valid(); ++it) { container.push_back(a); } |
marci@9 | 29 |
} |
marci@9 | 30 |
void put(node_iterator nit, const T& a) { container[G.id(nit)]=a; } |
marci@9 | 31 |
T get(node_iterator nit) { return container[G.id(nit)]; } |
marci@9 | 32 |
}; |
marci@9 | 33 |
|
marci@9 | 34 |
template <typename graph_type, typename T> |
marci@9 | 35 |
class edge_property_vector { |
marci@19 | 36 |
typedef typename graph_type::edge_iterator edge_iterator; |
marci@19 | 37 |
typedef typename graph_type::each_edge_iterator each_edge_iterator; |
marci@9 | 38 |
graph_type& G; |
marci@9 | 39 |
std::vector<T> container; |
marci@9 | 40 |
public: |
marci@9 | 41 |
edge_property_vector(graph_type& _G) : G(_G) { |
marci@9 | 42 |
int i=0; |
marci@19 | 43 |
for(each_edge_iterator it=G.first_edge(); it.valid(); ++it) ++i; |
marci@9 | 44 |
container.resize(i); |
marci@9 | 45 |
} |
marci@9 | 46 |
edge_property_vector(graph_type& _G, T a) : G(_G) { |
marci@19 | 47 |
for(each_edge_iterator it=G.first_edge(); it.valid(); ++it) { |
marci@9 | 48 |
container.push_back(a); |
marci@9 | 49 |
} |
marci@9 | 50 |
} |
marci@9 | 51 |
void put(edge_iterator eit, const T& a) { container[G.id(eit)]=a; } |
marci@9 | 52 |
T get(edge_iterator eit) { return container[G.id(eit)]; } |
marci@9 | 53 |
}; |
marci@9 | 54 |
|
marci@9 | 55 |
} // namespace marci |
marci@9 | 56 |
|
marci@9 | 57 |
#endif //MARCI_PROPERTY_VECTOR_HH |