src/work/marci_property_vector.hh
author athos
Thu, 18 Mar 2004 16:50:07 +0000
changeset 201 b9158a014fe8
parent 19 3151a1026db9
permissions -rw-r--r--
Alp?r javaslat?ra k?sz?tettem egy strukt?r?t 2 dimenzi?s vektorok (s?kvektorok) t?rol?s?ra. Olyasmiket tud, amiket s?kvektorokt?l szeretn?nk. A neve: xy, a hasonl? nevu .h file-ban tal?lhat?.
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
alpar@107
     6
namespace hugo {
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 {
alpar@107
    17
    typedef typename graph_type::node_iterator node_iterator;
alpar@107
    18
    typedef typename graph_type::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
alpar@107
    55
} // namespace hugo
marci@9
    56
marci@9
    57
#endif //MARCI_PROPERTY_VECTOR_HH