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