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