Home | Documentation | Download | Platforms | Projects | Mailing Lists | Version History
00001 //========================================================================== 00002 // 00003 // ne_map.h - common implementation of node_map and edge_map 00004 // 00005 //========================================================================== 00006 // $Id: ne_map.h,v 1.20 2005/06/14 12:22:12 raitner Exp $ 00007 00008 #ifndef GTL_NE_MAP_H 00009 #define GTL_NE_MAP_H 00010 00011 #include <GTL/GTL.h> 00012 00013 #include <vector> 00014 #include <cassert> 00015 00016 //-------------------------------------------------------------------------- 00017 // Class declaration 00018 //-------------------------------------------------------------------------- 00019 00020 __GTL_BEGIN_NAMESPACE 00021 00029 template <class Key, class Value, class Graph, class Alloc = allocator<Value> > 00030 class ne_map 00031 { 00032 protected: 00033 00034 //================================================== Constructors 00035 00040 ne_map(); 00041 00053 explicit ne_map(const Graph &g, Value def=Value()); 00054 00055 //================================================== Operations 00056 00057 public: 00058 00066 void init(const Graph &, Value def=Value()); 00067 00071 #if defined(__GTL_MSVCC) && _MSC_VER < 1310 00072 typedef Value& value_reference; 00073 #else 00074 typedef typename vector<Value, Alloc>::reference value_reference; 00075 #endif 00076 00080 #if defined(__GTL_MSVCC) && _MSC_VER < 1310 00081 typedef const Value& const_value_reference; 00082 #else 00083 typedef typename vector<Value, Alloc>::const_reference const_value_reference; 00084 #endif 00085 00103 value_reference operator[](Key key); 00104 00120 const_value_reference operator[](Key key) const; 00121 00125 void clear (); 00126 00127 //================================================== Implementation 00128 00129 private: 00130 vector<Value, Alloc> data; 00131 }; 00132 00133 // Implementation Begin 00134 00135 template <class Key, class Value, class Graph, class Alloc> 00136 ne_map<Key,Value,Graph,Alloc>::ne_map() 00137 { 00138 } 00139 00140 template <class Key, class Value, class Graph, class Alloc> 00141 ne_map<Key,Value,Graph,Alloc>::ne_map(const Graph &g, Value t2) : 00142 data(g.number_of_ids(Key()), t2) 00143 { 00144 } 00145 00146 template <class Key, class Value, class Graph, class Alloc> 00147 void ne_map<Key,Value,Graph,Alloc>::init(const Graph &g, Value t2) 00148 { 00149 int n = g.number_of_ids(Key()); 00150 data.resize(n); 00151 fill_n(data.begin(), n, t2); 00152 } 00153 00154 template <class Key, class Value, class Graph, class Alloc> 00155 typename ne_map<Key,Value,Graph,Alloc>::value_reference ne_map<Key,Value,Graph,Alloc>::operator[](Key t1) 00156 { 00157 if(t1.id() >= (signed)data.size()) 00158 { 00159 if (t1.id() >= (signed)data.capacity()) { 00160 data.reserve((6 * t1.id()) / 5 + 1); 00161 } 00162 00163 data.insert(data.end(), t1.id()+1-data.size(), Value()); 00164 } 00165 return data.operator[](t1.id()); 00166 } 00167 00168 template <class Key, class Value, class Graph, class Alloc> 00169 typename ne_map<Key,Value,Graph,Alloc>::const_value_reference ne_map<Key,Value,Graph,Alloc>::operator[](Key t1) const 00170 { 00171 assert(t1.id() < (signed)data.size()); 00172 return data.operator[](t1.id()); 00173 } 00174 00175 template <class Key, class Value, class Graph, class Alloc> 00176 void ne_map<Key,Value,Graph,Alloc>::clear () 00177 { 00178 data.clear(); 00179 } 00180 00181 // Implementation End 00182 00183 __GTL_END_NAMESPACE 00184 00185 #endif // GTL_NE_MAP_H 00186 00187 //-------------------------------------------------------------------------- 00188 // end of file 00189 //--------------------------------------------------------------------------
University of Passau - FMI - Theoretical Computer Science